3 ms·
How would you get sed to output the files and lines on which replacements happened?
by parfe 14y ago
How would you get sed to output the files and lines on which replacements happened?
- noste 14y agoHow about using diff and sed -i? # This version is obviously unsafe verbose_sed() { sed -i.old -e "$1" "$2" diff -u "$2.old" "$2" rm "$2.old" } verbose_sed s/vim/emacs/g rant.txt You could then use all the tools that we already have for working with patches: colordiff to colorize the output, diffstat for a summary of changes, patch -R for reverting the changes, and so on. Of course, you're more likely to than not already using version control, which gives you all this and much more, even if you were to use vanilla find+sed.