matthew@gizmo.UK.Sun.COM (Matthew Buller - Sun EHQ - MIS) (05/03/91)
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
rbj@uunet.uu.net (Root Boy Jim) (05/18/91)
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 > >I have tried to grok the man page for `sed' but no luck. Try a bit harder. Or buy a book such a "Sed & Awk" from O'Reilly & Associates. In the meantime, here is the solution: sed -n '/pat1/,/pat2/p' also sed '/pat1/,/pat2/!d' Be aware that this will select all non-overlapping ranges, so you may get more than you want. Basicly, all the lines in the sed 'program' are executed on every line of the input file. It's really pretty simple. However, my eyes glazed over the first time I read the words "pattern space". -- [rbj@uunet 1] stty sane unknown mode: sane