Re: sed - replacing a block of text with a line.
From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 11/18/03
- Next message: Christoph Schuch: "Re: sed - replacing a block of text with a line."
- Previous message: sunil: "sed - replacing a block of text with a line."
- In reply to: sunil: "sed - replacing a block of text with a line."
- Next in thread: Alan Connor: "Re: sed - replacing a block of text with a line."
- Reply: Alan Connor: "Re: sed - replacing a block of text with a line."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Christoph Schuch: "Re: sed - replacing a block of text with a line."
- Previous message: sunil: "sed - replacing a block of text with a line."
- In reply to: sunil: "sed - replacing a block of text with a line."
- Next in thread: Alan Connor: "Re: sed - replacing a block of text with a line."
- Reply: Alan Connor: "Re: sed - replacing a block of text with a line."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|