![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
grep all lines from PATTERN1 to PATTERN2
Hi!
From a file like this one : Code:
hello ... PATTERN1 ... lines between patterns .. PATTERN2 ... Thanks a lot for your help, Tipi |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Some possibilities:
Code:
sed -n '/PATTERN1/,/PATTERN2/p' file Code:
awk '/PATTERN1/{f=1}/PATTERN2/{f=0;print}f' file
|
|
#3
|
|||
|
|||
|
Thanks!
|
|
#4
|
|||
|
|||
|
Can we modify it so that patterns dont appear in the output?
Thanks again! |
|
#5
|
|||
|
|||
|
Quote:
Code:
awk '/PATTERN1/{f=1;next}/PATTERN2/{exit}f' file
|
|
#6
|
|||
|
|||
|
Very appreciated!
|
|||
| Google The UNIX and Linux Forums |