Robert Buchholz wrote: > On Tuesday, 25. September 2007, Donnie Berkholz wrote: >> On 20:04 Mon 24 Sep , Doug Goldstein (cardoe) wrote: >> > if ! use usb; then >> > sed -i util/Makefile \ >> > -e '/ttusb_dec_reset/d' \ >> > -e '/dib3000-watch/d' >> > fi >> > >> > # do not compile test-progs >> > sed -i Makefile -e '/-C test/d' >> >> You might want to die if these seds fail. > > I already wondered a while back: > sed only fails if the file does not exist, but not if there was no > replacement. Is there any way to force it to? > ed will exit with an error if a regex doesn't match: ed -s util/Makefile <<< 'H /ttusb_dec_reset/d /dib3000-watch/d w q' || die 'ohNoes!'
I prefer to mute errors in an ebuild (after testing): ed -s Makefile 2>/dev/null <<< $'/-C test/d\nw\nq' \ || die 'No match in Makefile' ..which I think is a lot easier to grok than the sed convolutions. If it's supposed to be deleting every line with that regex (as the sed currently does) I'd use: $'g/-C test/d\nw\nq' I appreciate that ed seems hard (man ed is frightening!) but once you get used to here-strings (and $' expansion) it's a doddle. (Use ,p instead of w to see the output during testing.) Tutorial: http://bash-hackers.org/wiki/doku.php?id=howto:edit-ed Easier man page: http://plan9.bell-labs.com/magic/man2html/1/ed Reference: http://www.opengroup.org/onlinepubs/009695399/utilities/ed.html (I very much recommend that opengroup site as it outlines what a scripwriter or programmer can expect on any POSIX/SuS compliant system.) -- [EMAIL PROTECTED] mailing list