[OT] replace a word with a multiline with sed

Adam Hough adam at gradientzero.com
Thu May 13 19:31:44 UTC 2010


2010/5/13 Mohamed El Morabity <pikachu.2014 at gmail.com>

> Le jeudi 13 mai 2010 à 18:14 +0200, Gianluca Cecchi a écrit :
> > Hello,
> > sorry for the offtopic. it seems a simple thing but I can't find an
> > escape char or something correct...
> > I have this setup in place
> > source file input.txt:
> >
> > bla bla
> > bla bla
> > TAG
> > bla bla
> >
> > sed command file sed.txt:
> >
> > /TAG/c\
> > BLABLA .... BLABLA
> >
> > so that the command
> > sed -f sed.txt input.txt
> > gives as output
> >
> > bla bla
> > bla bla
> > BLABLA .... BLABLA
> > bla bla
> >
> > Suppose I want now to substitute the TAG pattern with a multi-line
> > pattern, for example
> > occurences of
> > TAG
> > must become 2 lines:
> > BLABLA
> > BLOBLO
> >
> > How can I achieve this?
> > Thanks in advance,
> >
> > Gianluca
>
> Hi,
>
> simply using the following pattern for sed?
>   /TAG/c\
>   BLABLA\nBLOBLO
>
>
>
> --
> users mailing list
> users at lists.fedoraproject.org
> To unsubscribe or change subscription options:
> https://admin.fedoraproject.org/mailman/listinfo/users
> Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
>
>
I have used something like that but I tend to do it through vi/vim with a
(crtl-v)(crtl-m) to get a ^M character.  So in vim it is "
%s:TAG:BLABLA(crtl-v)(crtl-m)BLOBLO: ".  It should work with sed as well but
the file I last used this one did not like me replacing the other special
character with the ^M but it would let me do it in vim with sed.

- Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.fedoraproject.org/pipermail/users/attachments/20100513/1ab49a49/attachment-0001.html 


More information about the users mailing list