easy for some
    Tom Armistead 
    toma at swsrv1.cirr.com
       
    Thu May  9 09:38:03 AEST 1991
    
    
  
In article <6686 at male.EBay.Sun.COM> matthew at 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 at swsrv1.cirr.com                {egsner,letni,ozdaltx,void}!swsrv1!toma
    
    
More information about the Comp.unix.wizards
mailing list