Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!mcsun!ukc!cf-cm!bharat From: bharat@computing-maths.cardiff.ac.uk (Bharat Mediratta) Newsgroups: comp.unix.wizards Subject: Re: easy for some Message-ID: <1991May9.161236.15081@cm.cf.ac.uk> Date: 9 May 91 16:12:36 GMT References: <6686@male.EBay.Sun.COM> <1991May8.233803.4485@swsrv1.cirr.com> Sender: news@cm.cf.ac.uk (USENET News System) Organization: University of Wales College of Cardiff Lines: 43 In article <1991May8.233803.4485@swsrv1.cirr.com> toma@swsrv1.cirr.com (Tom Armistead) writes: >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--- > >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---$' Well, if the patterns only occur once in the file, here's a simple sed solution: sed -e '1,/^pattern1---$/d' -e '/^pattern2---$/,$d' < data_file As you can see, it deletes all the stuff up to (and including) the first pattern, and then all the stuff from the second pattern (inclusive) to the end of the file. If you have multiple recurrences of this in the file, you only get the first one. -- | Bharat Mediratta | JANET: bharat@cm.cf.ac.uk | +--------------------+ UUNET: bharat%cm.cf.ac.uk%cunyvm.cuny.edu@uunet.uucp | |On a clear disk... | uk.co: bharat%cm.cf.ac.uk%cunyvm.cuny.edu%uunet.uucp@ukc| |you can seek forever| UUCP: ...!uunet!cunym.cuny.edu!cm.cf.ac.uk!bharat |