The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep and fetching lines after grep arghya_owen Shell Programming and Scripting 2 07-16-2008 04:25 AM
how to delete text from line starting pattern1 up to line before pattern2? repudi8or Shell Programming and Scripting 5 04-15-2008 06:25 PM
Grep two lines at a time joshjimda Shell Programming and Scripting 6 03-26-2008 12:18 PM
grep -n lines before and after airman_ole Shell Programming and Scripting 2 01-20-2008 10:33 PM
grep + lines after Janus Shell Programming and Scripting 4 11-03-2006 02:56 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-02-2008
Registered User
 

Join Date: Jul 2008
Location: Montreal
Posts: 33
grep all lines from PATTERN1 to PATTERN2

Hi!

From a file like this one :

Code:
hello
...
PATTERN1
...
lines between patterns
..
PATTERN2
...
I would like to extract only the lines between patterns, probably with awk I think?

Thanks a lot for your help,


Tipi
Reply With Quote
Forum Sponsor
  #2  
Old 09-02-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,204
Some possibilities:

Code:
sed -n '/PATTERN1/,/PATTERN2/p' file
Code:
awk '/PATTERN1/{f=1}/PATTERN2/{f=0;print}f' file
Regards
Reply With Quote
  #3  
Old 09-02-2008
Registered User
 

Join Date: Jul 2008
Location: Montreal
Posts: 33
Thanks!
Reply With Quote
  #4  
Old 09-02-2008
Registered User
 

Join Date: Jul 2008
Location: Montreal
Posts: 33
Can we modify it so that patterns dont appear in the output?

Thanks again!
Reply With Quote
  #5  
Old 09-02-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,204
Quote:
Originally Posted by tipi View Post
Can we modify it so that patterns dont appear in the output?

Thanks again!
Code:
awk '/PATTERN1/{f=1;next}/PATTERN2/{exit}f' file
Reply With Quote
  #6  
Old 09-02-2008
Registered User
 

Join Date: Jul 2008
Location: Montreal
Posts: 33
Very appreciated!
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0