A sed syntax

littlebat dashing.meng at gmail.com
Wed Jun 23 05:03:44 PDT 2010


On Wed, 23 Jun 2010 02:57:44 -0400
Neal Murphy <neal.p.murphy at alum.wpi.edu> wrote:

> 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 braces.
> 
> Good enough?
> -- 
> http://linuxfromscratch.org/mailman/listinfo/lfs-support
> FAQ: http://www.linuxfromscratch.org/lfs/faq.html
> Unsubscribe: See the above information page

Thanks. Good answer. Save me much time, with your help.

Always hate read the whole man page (info page) of those big program :-)

Got at least three from this:
1, Sed syntax: sed -e "/address/command"
2, command can be a 'compound command', it is {}
3, just forgot delimiter can be any character 

>   sed -e 's=^\(*cpp:\)=\1 -s system /tools/include/='

I modified it as below but can't achieve the effect:

sed -e "s=^\(*cpp:\)$=\1 -isystem /tools/include="

It only append " -isystem /tools/include" to the end of the line which
only include string "*cpp:". The book needs append the string to the
next line of the line only include string "*cpp:".

But, at least I have known more on sed. Thanks.

--
littlebat



More information about the lfs-support mailing list