[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: sed usage (was: automated editing of text files)



Tom Furie wrote:
> Bob Proulx wrote:
> > Using sed is a good tool for this but if you want to append then you
> > should use the 'a' command.
> > 
> >   $ printf "one\ntwo\nthree\nfour\n" | sed '/two/a\
> >   -> foo'
> >   one
> >   two
> >   -> foo
> >   three
> >   four
> 
> This doesn't quite work for me in this scenario either:
> 
> 	printf "<pre>\nSome text\n</pre>" | sed '/<pre>/a\n'

That is the wrong syntax.  You have quoted the 'n'.  That is why you
see the 'n' show up in the display.  Try this:

  printf "<pre>\nSome text\n</pre>\n" | sed '/<pre>/a\
  '

And by that I mean literally 'a' followed by a single backslash
followed by a single newline.  Just like in the example.  :-)

> P.S. Hmm, while testing before sending this I discovered that
> sed '/<pre>/a\\' works. Not what I would have expected.

That is an interesting quirk of GNU sed.  But note that other sed
implementations handle that differently.  It isn't portable.  For
example:

  sed: Function /<pre>/a\\ cannot be parsed.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: