When using sed
to perform an in-place edit on a directory I seem to always forget that zero length arguments require a space between the argument (an empty string, that is ''
or ""
) and the flag.
So this is incorrect:
$ grep -rl Trafficland . | xargs sed -i"" \
-e "s/Trafficland/TrafficLand/g"
You end up with a bunch of backup files with a *-e
extension.
This is correct:
$ grep -rl Trafficland . | xargs sed -i "" \
-e "s/Trafficland/TrafficLand/g"
Notice the critical space between the -i
flag and its empty string parameter.
The -i
flag is required to perform inline editing and furthermore it requires an argument on OSX (and probably BSD as well).
If you're operating within a source code repository then there's no need for a backup file for streamline edits unless you are diff-ing the original with the result to make sure your pattern doesn't do anything unanticipated.
Should you end up with a bunch of *-e
backups which require removal:
$ find . -type f -name "*-e" -exec rm {} \;