[UFO Chicago] Learning GNU/Sed

Adam Lazur adam@lazur.org
Sat, 22 Jun 2002 11:57:55 -0400


jjbenham@igor.chicagoguitar.com (jjbenham@igor.chicagoguitar.com) said:
> Don't laugh. Actually its okay if you do. I am not a CS major.
> sed -e "/^CFLAGS/ s/-O3/${CFLAGS}/" < makefile > makefile.hacked
> sed 's/\/usr\/local\/include/\/usr\/local/g' makefile.hacked > makefile.new
> sed 's/\/usr\/local\/lib/\/usr\/lib/g' makefile.new > makefile
>
> How can I do the same thing and make it less confusing to the reader?

I'd probably do something like the following:

sed -e "/^CFLAGS/s/-O3/${CFLAGS}/" \
    -e 's|/usr/local/include|/usr/local|g' \
    -e 's|/usr/local/lib|/usr/lib|g' \
    makefile > makefile.new
mv makefile.new makefile

Dunno if it's less confusing to "the reader", but it's simpler to me.
The use of s| instead of s/ for pathname subs is nice so you don't have
to escape the /'s all the time.

You mentioned you were doing this for Gentoo Linux. Is it possible to
fix these paths and flags by editting a master makefile elsewhere?

Oh, and I've heard the o'reilly sed & awk book isn't too bad, though I
don't personally own a copy.

-- 
Adam Lazur, Cluster Monkey