FW: [Gllug] Awk Sed

Alex Hudson home at alexhudson.com
Fri Dec 7 09:11:39 UTC 2001


On Fri, 2001-12-07 at 02:55, harry wrote:
> On Thursday 06 Dec 2001 7:50 pm, Alex wrote:
> >  Perl -p -i'.orig' -e 's/(Alex)/$1andria/g;' *
> 
> I did not entirely understand what you have done there as I am no Perl guru
> but  another technique I found while playing with sed is this. 

Sorry, I should have explained it better. Perl _will_ operate on files
in-place, by passing it -p. -i'.orig' says 'backup every file that you
touch before you change it, with the extension .orig', so file becomes
file.orig before file is changed. -e says 'execute this', and in this
case the 'this' is a replacement - changing every instance of Alex to
Alexandria. The final star is 'everything in this directory', as usual
;)

> Put the following in a shell script
> #! /bin/sh
> sed -e 's/'$2'/'$3'/g' $1 > $1ff; more $1ff > $1; rm $1ff; rm *~

Hmm. I think that I would check that sed had run successfully before
deleting the original file, but I suppose it doesn't matter hugely.

> I need to learn more Perl as it keeps coming up as the best utility for the
> job on more occasions than I care to remember.

Definitely :) 

Cheers,

Alex.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 240 bytes
Desc: not available
URL: <http://mailman.lug.org.uk/pipermail/gllug/attachments/20011207/03393b40/attachment.pgp>


More information about the GLLUG mailing list