问题
To replace all occurrences of a word with another in all files with a particular extension in the current directory I use this command:
find . -type f -name '*.zz' -exec sed -i '' "s/replace_this/with_this/" {} +
The problem is that it adds \n to the end of files that do not end in \n. Now don't get me wrong, I love \n terminated files as much as the next person. But I don't want all those changes in my git diff. What's a command to run that does the same thing but without touching file endings?
By the way I'm using emacs with counsel-projectile so if there's a handy tool there instead that would be fine.
macOS 10.13.4
回答1:
Give a try to perl pie instead of sed with something like this:
perl -pi -e 's/replace_this/with_this/"
In your case:
find . -type f -name '*.zz' -exec perl -pi -e "s/replace_this/with_this/" {} +
来源:https://stackoverflow.com/questions/50122548/replace-all-occurrences-without-changing-file-endings