find . -type f -name "test.php" -print0 | xargs -0 egrep -sHnl "&\s*new\s"| xargs gsed -i.bak 's/&\(\s*new\s\)/\1/gi' -
This works fine to replace the selected file.
But I want to look at the difference between the original and replaced files at the same time.
find . -type f -name "test.php" -print0 | xargs -0 egrep -sHnl "&\s*new\s"| xargs gsed -i.bak 's/&\(\s*new\s\)/\1/gip' -
This attempt fails, but also duplicate the lines which are replaced.
find . -type f -name "test.php" -print0 | xargs -0 egrep -sHnl "&\s*new\s"| xargs gsed -n 's/&\(\s*new\s\)/\1/p' -
This works but do neither overwrite the original file( i.e. not makes it change with replaced text) nor backup.
With this inspiration, I tried following, but doesn't work.
find . -type f -name "test.php" -print0 | xargs -0 egrep -sHnl "&\s*new\s"| xargs gsed -i.bak 's/&\(\s*new\s\)/\1/gip;s/.*\n//' -
How can I achieve it?