|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Display n lines before match found
I have a file with following data
A B C D E F G H I K L M N and search pattern is G Expected output A B C D E F Note : Apart from grep -B i need some other options |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
awk '/G/{exit}'1 file |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
Code:
awk '/G/{p=1}!p' file |
|
#4
|
|||
|
|||
|
Code:
sed -n '/G/q;p' Regards, Alister |
| The Following User Says Thank You to alister For This Useful Post: | ||
nsuresh316 (06-25-2012) | ||
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk display the match and 2 lines after the match is found. | eurouno | UNIX for Dummies Questions & Answers | 4 | 02-03-2012 08:16 PM |
| search and replace, when found, delete multiple lines, add new set of lines? | DeuceLee | Shell Programming and Scripting | 3 | 11-23-2011 03:39 PM |
| Perl script to look for a string in a file and append few lines if the match is found | arunkumarmc | Programming | 1 | 03-04-2011 05:05 PM |
| Grep and display n lines after the match is found. | cv_pan | UNIX for Dummies Questions & Answers | 3 | 09-25-2008 11:15 PM |
| if match found go to a particular line in perl | user_prady | Shell Programming and Scripting | 17 | 03-31-2008 03:00 PM |
|
|