Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!sun-barr!newstop!grapevine!male!jethro!exodus!appserv!slovax.Eng.Sun.COM!lm From: lm@slovax.Eng.Sun.COM (Larry McVoy) Newsgroups: comp.unix.wizards Subject: Re: easy for some Message-ID: <574@appserv.Eng.Sun.COM> Date: 8 May 91 20:01:14 GMT References: <6686@male.EBay.Sun.COM> Sender: news@appserv.Eng.Sun.COM Organization: Sun Microsystems, Mt. View, CA. Lines: 45 matthew@gizmo.UK.Sun.COM (Matthew Buller - Sun EHQ - MIS) writes: > problem: to extract text between start and end patterns in a file > eg:- > > file: > > pattern1--- > > stuff > stuff > stuff > > pattern2--- /bin/sh, usage shellscript start_pat stop_pat [files...] START=$1; shift STOP=$1; shift PRINT= cat $* | while read x do if [ "$x" = "$STOP" ] then exit 0; fi if [ "$x" = "$START" ] then PRINT=yes continue fi if [ X$PRINT != X ] then echo "$x"; fi done /bin/perl, same usage (see the notes on the ".." operator, cool thingy). $START = shift; $STOP = shift; while (<>) { if (/^$START$/../^$STOP/) { next if /^$START$/; # skip starting pattern last if /^$STOP/; # done if last; print; } } --- Larry McVoy, Sun Microsystems (415) 336-7627 ...!sun!lm or lm@sun.com