Re: sed problem...simpler solution?
From: Stephane CHAZELAS (this.address_at_is.invalid)
Date: 02/28/04
- Previous message: Stephane CHAZELAS: "Re: sed backreferences"
- In reply to: Mike Chirico: "sed problem...simpler solution?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Feb 2004 11:29:45 +0100
2004-02-27, 16:19(-05), Mike Chirico:
> Using sed, how do I print contents between delimiters
> <start> and <stop> if these delimiters sometimes occur on the same line?
> It's ok to include <start> and <stop> in the output.
Use perl instead of sed:
perl -p0777 -e 's/.*?<start>(.*?)<stop>/$1\n/sg' < file.txt
With sed:
sed -n '
:1
/<start>/!d
:2
/<start>.*<stop>/!{
N;b2
}
s/_/_u/g;s/(/_l/g;s/)/_r/g
s/<start>/(/g;s/<stop>/)/g
h;s/^[^(]*(\([^)]*\)).*/\1/
s/(/<start>/g;s/)/<stop>/g
s/_l/(/g;s/_r/)/g;s/_u/_/g
p;g;s/^[^(]*([^)]*)//
s/(/<start>/g;s/)/<stop>/g
s/_l/(/g;s/_r/)/g;s/_u/_/g;b1'
On an input like:
<start>1<stop><start>
2<stop><start><start><stop>
it gives:
1
2
<start>
-- Stéphane ["Stephane.Chazelas" at "free.fr"]
- Previous message: Stephane CHAZELAS: "Re: sed backreferences"
- In reply to: Mike Chirico: "sed problem...simpler solution?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]