🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.shell.unix.bourne-bash
Article #3

Re: how to replace multiple lines in a file?

#3
From: Michael Wang
Date: Tue, 10 Jun 2003 05:38
24 lines
2140 bytes
In article <9McFa.1192$PD3.13019@nnrp1.uunet.ca>,
Jeff Weeks <jweeks@mailandnews.com> wrote:
>For example, changing:
>[html]
><pre>
>
>to simply:
>[code]

These 11 lines work under ksh88, ksh93 and bash. Something shorter?

last=
while IFS= read -r curr; do
  if [[ $curr == *"<pre>"* && $last == *"[html]"* ]]; then
    printf "%s\n" "[code]"
    last=
  else
    [[ -n "$last" ]] && printf "%s\n" "${last#a}"
    last="a$curr"
  fi
done
printf "%s\n" "${last#a}"
-- 
Michael Wang * http://www.unixlabplus.com/ * mwang@unixlabplus.com
Technical Details
Message-ID: <N9eFa.367$6W4.90940@news.uswest.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news-out.visi.com!petbe.visi.com!feed.news.qwest.net!news.uswest.net.POSTED!not-for-mail
References: <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: f8c9b,bc0476873b7ef6e
X-Google-Attributes: gidf8c9b,public
X-Google-Thread: faa64,bc0476873b7ef6e
X-Google-Attributes: gidfaa64,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-09 22:39:01 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news-out.visi.com!petbe.visi.com!feed.news.qwest.net!news.uswest.net.POSTED!not-for-mail
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?
References: <9McFa.1192$PD3.13019@nnrp1.uunet.ca>
Organization: UnixLab Plus Inc, Jersey City, NJ
X-Newsreader: trn 4.0-test62 (21 February 1998)
From: mwang@unixlabplus.com (Michael Wang)
Lines: 24
Message-ID: <N9eFa.367$6W4.90940@news.uswest.net>
Date: Tue, 10 Jun 2003 05:38:53 GMT
NNTP-Posting-Host: 216.206.174.117
X-Trace: news.uswest.net 1055223533 216.206.174.117 (Tue, 10 Jun 2003 00:38:53 CDT)
NNTP-Posting-Date: Tue, 10 Jun 2003 00:38:53 CDT