3 ms·
however, perl has -i, which not all seds do, so those 0.002 seconds you lost to perl will be more than gained by being able to type perl -pi -e 's/foo/ba
by there 15y ago
however, perl has -i, which not all seds do, so those 0.002 seconds you lost to perl will be more than gained by being able to type
perl -pi -e 's/foo/bar/' somefile
instead of
sed 's/foo/bar/' somefile > somefile.tmp && mv somefile.tmp somefile
- pkrumins 15y agoSed has -i, too! Well, at least GNU sed.
- there 15y agoyes, that's why i said "not all seds".
- pkrumins 15y agomissed it. sorry!
- dramaticus3 15y agobecause GNU is Not Unix
- burgerbrain 15y agoThe utility 'sponge' is useful for doing this in the general case.
- AlecSchueler 15y agoPart of the 'moreutils' package, for the curious. The description for sponge on the project homepage reads "soak up standard input and write to a file."
- telemachos 15y agoRather than -i alone, I always use -i.bak (or whatever you prefer instead of '.bak'). That way, you get (1) in-place editing and (2) a backup. The files you work on are backed up to "file.bak", so that if you make some simple regex mistake with huge negative consequences, you have a ready fix. (And if you do things perfectly, it's easy to run "rm *bak" after you confirm that.)