sed matches too much? - sec-7.10 custom symlinks

akhiezer lfs65 at
Fri Feb 18 03:38:42 PST 2011

> Date: Thu, 17 Feb 2011 21:06:24 -0800
> From: Bryan Kadzban <bryan at>
> Subject: Re: sed matches too much? - sec-7.10 custom symlinks
> akhiezer wrote:
> >> Date: Thu, 17 Feb 2011 23:38:21 +0000
> >> From: akhiezer <lfs65 at>
> >> Subject: sed matches too much? - sec-7.10 custom symlinks
> >>
> >> In sub-section '7.10.1. CD-ROM symlinks', does the sed command match 
> >> too much: looks like the target file ends up with the following for 
> >> usb/firewire devices:
> >>
> >> PROGRAM="write_cd_rules by-id by-id"
> >>
> Argh, the rules changed.  That one wasn't there when the sed was written.
> As for the sed, I think the backreferences are getting a bit
> complicated.  Maybe it'd be simpler to just do something like this:
> s/"write_cd_rules"/"write_cd_rules mode"/
> Alternately, maybe match on GENERATED before the substitution, and rely
> on the fact that the usb/firewire rule is split across two lines?

I'd say try to avoid assuming line-break will be there: you could 
perhaps handle the possibility of line-breaks with a range-match, or 
'n' operator, or so - but then there's the risk that the sed can get a 
bit overly complex (wrt to the educational goals of the book) if you're 
really wanting to nail down the match rigourously.

Right now, as an immediate fix, the non-backref sed would be fine.

But either way, I'd suggest that the text ("If the default mode is not 
suitable ...") that precedes the sed code, should be re-considered in 
view of the target file now containing basically removable and fixed 
devices: what now do you want to demonstrate with the sed code? The 
present text is technically still correct, since it talks about the 
_default_ mode: but it's now perhaps a little unintentionally 



More information about the lfs-dev mailing list