Bash – How to echo changes made in a sed expression to the console

bashsed

I have a simple sed expression:

sed -i 's/foo/bar/g' blat.xml

Because the expression modifies the file in place it is hard to see which lines were changed.

Is there a way to echo the modified lines to the console?

Something similar to the output from the following would be ideal:

sed -n 's/foo/bar/gp' blat.xml

Best Answer

This is specific to GNU sed:

sed -i 's/foo/bar/gw /dev/stdout' blat.xml

You could use /dev/stderr instead.