The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 02-26-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by sank View Post
Hi all,

I am using sed for extracting the lines that occurs between the 2 patterns using the following command:

sed -n '/pattern1/,/pattern2/' filename

The above command has no problem and works fine. But I was wondering if there is a way to quit sed when it has extracted the range at least once ? this is required because the file will have only one occurrence of the above pattern range and also the input file on which sed operates is big.

Code:
sed -n -e '/pattern1/,/pattern2/' -e '/pattern2/q' filename