sed question
David W. Tamkin
dattier at vpnet.chi.il.us
Fri May 17 10:24:33 AEST 1991
rouben at math16.math.umbc.edu (Rouben Rostamian) wrote in
<1991May16.043510.16184 at umbc3.umbc.edu>:
| In article <3880 at wb3ffv.ampr.org> wmark at wb3ffv.ampr.org (Mark Winsor) writes:
| >I know that
| >
| >sed -n '/PATTERN1/,/PATTERN2/p' filename
| >
| >will print everything between pattern 1 & 2, but what if I only want the
| >first occurence of these patterns in the file? I know I can pipe the above
| >statement to sed '/PATTERN2/q' but there has got to be a way to do this
| >in one sed process. Thanks.
| Here it is -- one sed process:
|
| sed -n -e '
| /PATTERN1/,/PATTERN2/{
| p
| :loop
| n
| /PATTERN2/!{
| p
| bloop
| }
| p
| q
| }' <filename
sed -n '/PATTERN1/,/PATTERN2/p
/PATTERN2/q' filename
David Tamkin PO Box 7002 Des Plaines IL 60018-7002 dattier at vpnet.chi.il.us
GEnie:D.W.TAMKIN CIS:73720,1570 MCIMail:426-1818 708 518 6769 312 693 0591
More information about the Comp.unix.shell
mailing list