[lug] using sed.

Tkil tkil at scrye.com
Mon Nov 6 11:11:18 MST 2000

>>>>> "Chris" == Chris Riddoch <socket at peakpeak.com> writes:

Chris> English translation, for the German-impaired:

heh.  i got most of the german, but it's just as easy to reply to
yours.  :)

Chris> What that script doesn't do is change the original file..  How
Chris> can that be done again?

well, as Ralf points out, perl's "-i" switch handles this easily.  the
example used is a bit broken, however, since anything immediately
after the "-i" is used as the suffix for the original verrsion of the
file.  thus, i tend to use something like this:

   perl -i~ -pe 's/foo/bar/g' file1 file2 file3 ...

if you don't want to use perl, you can do this sort of thing with just
shell scripting:

   for i in file1 file2 file3 ; 
       sed -e 's/foo/bar/g' $i > $i.out && mv $i $i~ && mv $i.out $i

or similar.


More information about the LUG mailing list