Re: sed - replacing a block of text with a line.

From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 11/18/03


Date: Tue, 18 Nov 2003 10:02:26 GMT

On Tue, 18 Nov 2003 22:16:59 +1300, sunil <fingersmalloyNO_SPAM@yahoo.co.nz> wrote:
>
>
> Hello.
>
> I would like to be able to use sed for a substitute operation.
> I would like the script or command to iterate through all
> files in a dir, removing a block of text and replacing it
> with a single line.
>
> The files in question are html files for a web site.
> The blocks are stylesheets, that I wish to replace
> with a link to an external stylesheet.
>
> Unfortunalty, I am new to sed and regex.
> I couldn't find anything obvious in the sed manuals
> that shows how to perform a substitute operation
> from multiple lines to a single line.
>
> I gratefully welcome any 'RTFM' pointers, that will direct
> me to points of relevance I can use to craft a solution.
> I even more gratefully welcome accompanying solutions that
> I can learn from.
>
> I am using gnu sed version 3.02
>
> Thank you.
>
                                 
With AAA representing the tag that identifies the beginning of the
style sheets, and BBB the tag that identifies the end, and CCC being
the line to be inserted:

$ for file in *; do sed -f sedfile $file ; don

sedfile (doesn't need to be executable)

/AAA/i\
CCC

/AAA/,/BBB/d

We find the first line of the stylesheet and insert the line
before it, then delete the block.

There may be some issues with characters special to the shell, so
better post those tags.

AC



Relevant Pages

  • Re: CGIs & CSS - References
    ... I make a complete url to the stylesheet in my personal web space - a partial ... or a full ref to the global web space doesn't work. ... fails in the same way your CGI script does? ... Inside my head tag I have this. ...
    (perl.beginners)
  • Re: Customizing ASP.NEt Hyperlink Control
    ... "Mythran" wrote: ... >> doesn't supports the tag. ... >> stylesheet created by Visual Studio for a control. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Customizing ASP.NEt Hyperlink Control
    ... I have not been able to get rid of the underline from the hypelink control. ... I am using Visual Studio Enterprise Architect 2003. ... doesn't supports the tag. ... However in the default Stylesheet created by Visual Studio I found a class ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: <DIV> color
    ... > Yes - you can do that in two ways, inline and in a stylesheet. ... > so your inline code would be - ... I am new to the tag,> i ...
    (microsoft.public.frontpage.client)
  • Re: <DIV> color
    ... Yes - you can do that in two ways, inline and in a stylesheet. ... so your inline code would be - ... I am new to the tag, i> have always used tables so am not sure if i can even do it. ... after writing that do i need to put a 1 cell table in it and> background-color it? ...
    (microsoft.public.frontpage.client)