Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!convex!egsner!swsrv1!toma From: toma@swsrv1.cirr.com (Tom Armistead) Newsgroups: comp.unix.wizards Subject: Re: easy for some Message-ID: <1991May8.233803.4485@swsrv1.cirr.com> Date: 8 May 91 23:38:03 GMT References: <6686@male.EBay.Sun.COM> Organization: Software Services: Garland, Tx Lines: 41 In article <6686@male.EBay.Sun.COM> matthew@gizmo.UK.Sun.COM (Matthew Buller - Sun EHQ - MIS) writes: > >I am fairly new to unix, and I have a minor question:- >problem: to extract text between start and end patterns in a file >eg:- > >file: > >pattern1--- > >stuff >stuff >stuff > >pattern2--- > >How do I write a short script (preferably /bin/sh) to extract the information >between the start and end patterns (pattern1/pattern2) into a file. > >I have tried to grok the man page for `sed' but no luck. > >Any help would be appreciated. > >Tnx >Matt You could do this with sed. $ sed -n '/^pattern1---$/,/^pattern2---$/p' < data_file One problem with this is that it prints out the start and end parameters. You may be able to tell SED not to do this, but I don't know how. So I use egrep. $ sed -n '/^pattern1---$/,/^pattern2---$/p' < data_file | \ egrep -v '^pattern1---$|^pattern2---$' Tom -- Tom Armistead - Software Services - 2918 Dukeswood Dr. - Garland, Tx 75040 =========================================================================== toma@swsrv1.cirr.com {egsner,letni,ozdaltx,void}!swsrv1!toma