[conspire] vim vs sed awk and grep + interactive vs automation [was Re: Slice of life]

Rick Moen rick at linuxmafia.com
Tue Sep 22 00:00:43 PDT 2009


Quoting Tony Godshall (tony at of.net):

> I was just going to say...
> 
> Try translating this into sed:
>   perl -i -pe 's{/usr/local/bin/python}{/usr/bin/python2.4}' /usr/local/bin/*.py
> 
> But then I looked at a sed manual and saw you can do:
> 
>   s_/usr/local/bin/python_/usr/bin/python2.4_

You know something?  I'd seen that trick a few times, but kind of
ignored it.  The first time I found myself writing fugliness like

   sed -e 's/\/usr\/local\/bin\/'d foo

...I had the same reaction as yours of "Sod this for a lark, mate", except
that my own sidestep was to "awk -F/", rather than switching to Perl. 

Anyway, thank you for reminding me that "/" is merely sed's _usual_ 
field delimiter, such that one can specify anything else through the
simple expedient of putting any such something-else after the "s".  More
at:

http://www.grymoire.com/Unix/Sed.html#uh-2

Also worth mentioning:  The referenced tutorial suffers the usual old-Unix
brain damage of sticking to

    sed 's[something]' < oldfile > newfile 

...notation.  Which is all nicely 1974 and extremely portable, I'm sure,
but, frankly, screw that.  GNU sed added inline editing, and practically
all others have gradually followed suit.  Here in 2009-land, if an
implementation in front of me still doesn't do "sed -i" (inline), I'm
prepared to reformat the hard drive on the spot, to fix that problem.





More information about the conspire mailing list