Article View: alt.comp.lang.shell.unix.bourne-bash
Article #4Re: how to replace multiple lines in a file?
From: Walter Briscoe
Date: Tue, 10 Jun 2003 11:30
Date: Tue, 10 Jun 2003 11:30
55 lines
3338 bytes
3338 bytes
WTF is this doing in 8 newsgroups?
Peter S Tillier <peter_tillier@despammed.com> wrote a response in
comp.unix.shell which was invisible to me in comp.unix.programmer.
The cause of that was the "expletive deleted" OP. My work largely
duplicates Peter's. It would not have been done if Peter had followed
the OP's inanity.
In message <9McFa.1192$PD3.13019@nnrp1.uunet.ca> of Tue, 10 Jun 2003
00:03:06 in comp.unix.programmer, Jeff Weeks <jweeks@mailandnews.com>
writes
>Hello,
>
>I have a file, in a certain format grammer, which I wish to convert to
>another grammer, and I'm having trouble converting expressions that span
>multiple lines:
>
>For example, changing:
>[html]
><pre>
>
>to simply:
>[code]
>
>I can't seem to use regular expressions to find the initial multi-line item.
>I'm also confused as to which utility I should be using to accomplish this.
>I assumed sed would be the best tool for the task, but I'm not overly
>familiar with it, so perhaps I'm wrong?
Others have (implicitly) suggested you RTFM. I explicitly say so.
I learnt a lot from O'Reilly's (pub) "sed and awk" book by Linda Lamb.
Meanwhile, the following shows a solution for the example problem.
C:\WINNT\Temp>bash
bash-2.05b$ sed '/^\[html\]$/{N;/\n<pre>$/s/.*\n.*/[code]/;}' < data
[code]
[html]
irrelevant line
<pre> irrelevant line
bash-2.05b$ cat data
[html]
<pre>
[html]
irrelevant line
<pre> irrelevant line
bash-2.05b$ exit
exit
C:\WINNT\Temp>
sed provides very little to help you debug. = and l (ell) commands
inserted in the script where you are interested can help a lot.
--
Walter Briscoe
Technical Details
Message-ID:
<IfjVRWXFFc5+EwpK@ponle.demon.co.uk>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!freenix!proxad.net!peer1.news.newnet.co.uk!peer1.news.newnet.co.uk!kibo.news.demon.net!news.demon.co.uk!demon!ponle.demon.co.uk!wbriscoeReferences:
<9McFa.1192$PD3.13019@nnrp1.uunet.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114230,bc0476873b7ef6e X-Google-Attributes: gid114230,public X-Google-Thread: faa64,bc0476873b7ef6e X-Google-Attributes: gidfaa64,public X-Google-Thread: f8c9b,bc0476873b7ef6e X-Google-Attributes: gidf8c9b,public X-Google-Thread: fc89c,bc0476873b7ef6e X-Google-Attributes: gidfc89c,public X-Google-Thread: 1012a6,bc0476873b7ef6e X-Google-Attributes: gid1012a6,public X-Google-Thread: fee36,bc0476873b7ef6e X-Google-Attributes: gidfee36,public X-Google-Thread: 10f717,bc0476873b7ef6e X-Google-Attributes: gid10f717,public X-Google-Thread: 10183f,bc0476873b7ef6e X-Google-Attributes: gid10183f,public X-Google-ArrivalTime: 2003-06-10 09:28:16 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-08!supernews.com!freenix!proxad.net!peer1.news.newnet.co.uk!peer1.news.newnet.co.uk!kibo.news.demon.net!news.demon.co.uk!demon!ponle.demon.co.uk!wbriscoe From: Walter Briscoe <wbriscoe@ponle.demon.co.uk> Newsgroups: alt.comp.lang.shell.unix.bourne-bash,alt.os.linux,alt.unix.geeks,ca.unix,comp.unix,comp.unix.programmer,comp.unix.questions,comp.unix.shell Subject: Re: how to replace multiple lines in a file? Date: Tue, 10 Jun 2003 12:30:13 +0100 Lines: 55 Message-ID: <IfjVRWXFFc5+EwpK@ponle.demon.co.uk> References: <9McFa.1192$PD3.13019@nnrp1.uunet.ca> NNTP-Posting-Host: ponle.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain;charset=us-ascii X-Trace: news.demon.co.uk 1055262493 4630 194.222.194.7 (10 Jun 2003 16:28:13 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Tue, 10 Jun 2003 16:28:13 +0000 (UTC) User-Agent: Turnpike/6.02-U (<rq8rxKjVGtMiYN2c4l2LNUa4Mz>)