You could use sed
's w
flag with either /dev/stderr
, /dev/tty
, /dev/fd/2
if supported on your system. E.g. with an input file
like:
foo first
second: missing
third: foo
none here
running
sed -i '/foo/{
s//bar/g
w /dev/stdout
}' file
outputs:
bar first
third: bar
though file
content was changed to:
bar first
second: missing
third: bar
none here
So in your case, running:
find . -type f -printf '\n%p:\n' -exec sed -i '/foo/{
s//bar/g
w /dev/fd/2
}' {} \;
will edit the files in-place and output:
./file1:
bar stuff
more bar
./file2:
./file3:
bar first
third: bar
You could also print something like original line >>> modified line
e.g.:
find . -type f -printf '\n%p:\n' -exec sed -i '/foo/{
h
s//bar/g
H
x
s/\n/ >>> /
w /dev/fd/2
x
}' {} \;
edits the files in-place and outputs:
./file1:
foo stuff >>> bar stuff
more foo >>> more bar
./file2:
./file3:
foo first >>> bar first
third: foo >>> third: bar