[prog] using sed on multiple files
jennyw
jennyw at dangerousideas.com
Sun Jul 10 17:32:50 EST 2005
I'd guess that Finne's suggestion about -i would work ... I know I use it
that way with Perl or Ruby (sorry, I don't know sed very well at all). The
only additional suggestion I could make is that maybe you'd have more
flexibility using xargs?
To replace a string in a bunch of files, I normally use the in-place-edit
option (which is -i in both Perl and Ruby as well as, apparently, sed) along
with find and xargs. For example, to substitute "find" with "replace" in all
files ending in .txt, I'd do this (using Ruby):
find . |grep -i "\.txt$" | xargs ruby -p -i -e 'gsub(/find/i, "replace")'
or, with Perl:
find . |grep -i "\.txt$" | xargs perl -p -i -e "s/find/replace/gi"
Jen
More information about the Programming
mailing list