slj@mtung.ATT.COM (S. Luke Jones) (12/07/88)
I think I provided too much detail in my previous posting. Let's assume
we have a text file
blah blah SUDAN blah
blah blah CZECHOSLOVAKIA blah
blah blah MALAYSIA blah
blah blah CANADA blah
blah blah PERU blah
Suppose I want to grab everything between CZECHOSLOVAKIA to PERU, not
counting PERU. I *don't* know anything about the order of countries
in this file and I *don't* know that CANADA is the line before PERU.
sed -n '/CZECH/,/PERU/p'
gives me what I want except it includes the line with PERU. By
contrast,
awk '/CZECH/,/PERU/'
prints precisely the lines I want, i.e., it does not include PERU.
Any suggestions?
--
S. Luke Jones
AT&T Infor#####Bell Labs
200 Laurel Avenue, Room MT 2E-337, Middletown, NJ 07748
slj@mtung.att.com -or- ...!att!mtung!slj (201)-957-2733pjh@otter.hpl.hp.com (Patrick Hyland) (12/08/88)
The following will do what you want if you're using Bourne shell:
sed -n -e '
/CZECH/{
: loop
p
n
/PERU/!b loop
}
' filename
Thanks to Maarten Litmaath for posting the original
suggestion from which this is derived.
Patrick Hyland.wu@spot.Colorado.EDU (WU SHI-KUEI) (12/09/88)
In article <1076@mtung.ATT.COM> slj@mtung.UUCP (S. Luke Jones) writes: >I think I provided too much detail in my previous posting. Let's assume >we have a text file > blah blah SUDAN blah > blah blah CZECHOSLOVAKIA blah > blah blah MALAYSIA blah > blah blah CANADA blah > blah blah PERU blah >Suppose I want to grab everything between CZECHOSLOVAKIA to PERU, not >counting PERU. [ stuff deleted, including an awk command that does NOT work ] Instead of sed or awk, just use *ed*!!!! echo "/CZECH/,/PERU/-p" | ed - foo ^ Just a guest here. In reality: Carl Brandauer uunet!nbires!bdaemon!carl