ben at linuxgazette.net
Sat Jun 6 09:52:59 MSD 2009
[Gerry, please remember to include the list in the CC.]
On Fri, Jun 05, 2009 at 11:03:44PM -0500, Papciak, Gerard (Gerry) wrote:
> OK...you indicated sed -i 's/\<whs\>/&2/g' *
> 1st source of confusion: \<whs\ ....I understand the backslashes can
> act as 'delimiters', but why the '<'-sign?
They're not delimiters; that would be the forward slashes. '\<word\>' is
a construct used to define a stand-alone word rather than a string:
echo 'foobar'|sed 's/\<foo\>/xyz/' # Still 'foobar'
echo 'foo bar'|sed 's/\<foo\>/xyz/' # Now, it's 'xyz bar'
> SIMPLER CASE to HELP ME GET THIS...
> fisw1pd2 /export/home/c3782/TEST> sed -i 's/rr/zz/g' *
> sed: illegal option -- i
Whoops - you've got an older version of 'sed'.
ben at Jotunheim:~$ sed --version
GNU sed version 4.1.5
That's why I sent along the two different examples.
> I have 5 files in a directory: a.dat, b.dat, c.dat, d.dat, e.dat.
> Each contains: larry, gerry, diane, marianne, john, wally in separate
> I want to make each file look like this: lazzy, gezzy, diane, marianne,
> john, wally.
I'll quote myself from my previous email:
> for file in *
> /usr/bin/sed 's/\<whs\>/&2/g' $file > $file.NEW
> /bin/mv $file.NEW $file
It would work the same way for the above case:
for file in *
/usr/bin/sed 's/rr/zz/g' $file > $file.NEW
/bin/mv $file.NEW $file
Or, as Faber mentioned, you could use Perl. It's had that '-i' option
for a long time now.
perl -i~ -wpe 's/rr/zz/g' *
This will make your desired changes in all the files, saving the
originals with a '~' extension. If you don't want the backups, then just
leave off the '~'.
* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://LinuxGazette.NET *
More information about the TAG