Batch-correct files?
June 29, 2004 12:34 PM
Subscribe
sed: How do I use it to do a general search/replace on a bunch of files? The docs seem to believe all I have to do is feed it s/regexp/replacetext/g and a list of files and I'm off to the races, but rather than getting the files changed...
[exciting conclusion inside]
... rather than changing the files, it just spits all of the changed lines to stdout.
So... if file "one" contains:
the quick brown fox jumped over the lazy dog
and file "two" contains:
the grove of trees was interesting
Then: sed s/the/an/g *
gives me:
an quick brown fox jumped over an lazy dog
an ash grove
Which would be great if I wanted to concatenate all the results into a single file, but I don't. I want the changed results to sit in their source files. Without resulting to something like find . -exec sed s/the/an/gw{} {} \; -freak -I -dont -understand -unix.
Of course, I'd also like world peace and a pony.
posted by namespan to computers & internet (7 comments total)
perl -pi -e 's|foo|bar|g' *posted by greasepig at 12:50 PM on June 29, 2004