A sed syntax

Neal Murphy neal.p.murphy at alum.wpi.edu
Tue Jun 22 23:57:44 PDT 2010

On Wednesday 23 June 2010 02:24:51 littlebat wrote:
> Hi,
> I am learning LFS BOOK:
> http://www.linuxfromscratch.org/lfs/view/6.6/chapter05/adjusting.html
> Below is a sed syntax I can't understand and haven't found a place to
> learn it.
> <code>
> sed -e "/^\*cpp:$/{n;s,$, -isystem /tools/include,}"
> </code>

Basically, '/^\*cpp:$/' is the address that matches lines that contain 
exactly '*cpp:'. The braces indicate a 'compound command'. 'n;s' means 
execute those two commands (n: print the pattern space; s: substitute the EOL 
with the 'option'). The effect is, as you know, to append the option to the 
end of all lines with just '*cpp:' on them.

The commas are an unusual selection, but perfectly valid, since the s command 
allows pretty much any character to delimit the match and replace phrases.

This could be rewritten as
  sed -e 's=^\(*cpp:\)=\1 -s system /tools/include/='
which would be a little more grokable.

The only thing you need to find in the manual is the definition and use of the 

Good enough?

More information about the lfs-support mailing list