sed replacement

Kevin D. Clark clark_k at pannaway.com
Mon May 16 11:06:48 EDT 2005


Robert La Ferla <robertlaferla at comcast.net> writes:

> BTW - That should have been:
>
> cat myfile | sed -e "s/text/\n\ntext/"
>
> but it still doesn't work...

I would do this:
(warning:  there are embedded newlines here)

sed -e 's/text/\
\
text/' myfile

Let me be more illustrative:

sed -e 's/text/\<-LINE ENDS HERE
\<-LINE ENDS HERE
text/' myfile

That's how it is with sed.  OBTW, with some versions of sed your
original might even work.  I am interested in portable sed scripts
though, so I would never rely upon this fact.

In contrast, here is how it would be in Perl:

  perl -pe 's/text/\n\ntext/' myfile

Hope this helps.

Just another Perl hacker,

--kevin
-- 
GnuPG ID: B280F24E                     And the madness of the crowd
alumni.unh.edu!kdc                     Is an epileptic fit
                                       -- Tom Waits



More information about the Discuss mailing list