|
|||||||
| 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 after match found and other line
I have a file like this Code:
DoctorName Address1 Address2 DOB InsuredName Address1 Address2 DOB PatientName Address1 Address2 DOB ClaimNo1 DoctorName Address1 Address2 DOB InsuredName Address1 Address2 DOB PatientName Address1 Address2 DOB ClaimNo2 . . . (and this set of information gets repeated n times) I want to print the address1 under InsuredName & ClaimNO Expected Output Code:
Address1 ClaimNo1 Address1 ClaimNo2 . . Address1 ClaimNo(n) Note : My shell is csh, I am able to print the address1 under InsuredName alone using following command Code:
awk 'c-->0;/InsuredName/{c=1}' file
Last edited by zaxxon; 06-26-2012 at 06:52 AM.. Reason: code tags, see PM |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Based on the input file given.. Code:
$ nawk '/InsuredName/ {f=NR; getline; print} NR==f+8' infile
Address1
ClaimNo1
Address1
ClaimNo2 |
| The Following User Says Thank You to jayan_jay For This Useful Post: | ||
nsuresh316 (06-27-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
As per my previous input the pattern[claimno] comes 7 lines after search pattern[InsuredName]. I want to print the address1 under InsuredName & ClaimNO.But input scenario is different Code:
The pattern ClaimNO comes anywhere in the File Code:
DoctorName Address1 Address2 DOB InsuredName Address1 Address2 DOB ClaimNo1 PatientName Address1 Address2 DOB DoctorName Address1 Address2 DOB ClaimNo2 InsuredName Address1 Address2 DOB PatientName Address1 Address2 DOB . Code:
My shell is csh . . Last edited by nsuresh316; 07-16-2012 at 09:28 AM.. |
| 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 |
| Display n lines before match found | nsuresh316 | UNIX for Dummies Questions & Answers | 3 | 06-25-2012 09:04 AM |
| 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 |
| 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 |
|
|