Just a thought on sed

Chad Simmons polpak at yahoo.com
Fri May 3 09:08:47 PDT 2002

--- Marc Heerdink <marc at linuxfromscratch.org> wrote:
> Op vr 03-05-2002, om 05:36 schreef Rob 'Feztaa' Park:
> > In order to modify a file with sed, we have to use a tempfile (ie,
> > move the file then sed it back).
> > 
> > I suggest we simplify things a bit by using "perl -i -pe" instead of
> > sed. The -i option makes perl modify the file in place (no tempfile),
> > and the -pe bit makes perl act just like sed. So you could replace
> > something like this:
> > 
> >     mv file file~ &&
> >     sed 's/foo/bar/g' file~ > file &&
> >     rm file~
> We currently only have these constructs:
> mv file file.backup &&
> sed 's/foo/bar/g' file.backup >file
> thus saving a backup copy in case something went wrong. Modifying a file
> in place would only be possible if we'd do it like this:
> cp file file.backup &&
> perl -i -pe 's/foo/bar/g' file
> and we'd have 2 lines of commands anyway.
Actually, the options here allow you to specify a backup also..

perl -i.backup -pe 's/foo/bar/g' file

The above will accomplish the same as your 2 line version above

Chad Simmons

Version 3.1
GCS/L/C/O d-(+) s++:+ a-- C+++$>++++ UBLS++++$ 
P+++(--)$ L++>+++ E--- W+>++$ N !o K? w(--) !O 
M- !V PS+ PE(++) Y+ PGP->+ t- 5 X+() R(+) tv+@ 
b++(+++) !DI+++ D G(-) e>+++$ h---() r+++ y+++

Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-dev' in the subject header of the message

More information about the lfs-dev mailing list