Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


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 !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-26-2012
Registered User
 
Join Date: Jun 2012
Posts: 23
Thanks: 11
Thanked 0 Times in 0 Posts
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

Moderator's Comments:
Please use code tags, thanks!

Last edited by zaxxon; 06-26-2012 at 06:52 AM.. Reason: code tags, see PM
Sponsored Links
    #2  
Old 06-26-2012
jayan_jay's Avatar
Forum Advisor
 
Join Date: Jul 2008
Posts: 831
Thanks: 9
Thanked 185 Times in 176 Posts
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  
Old 06-27-2012
Registered User
 
Join Date: Jun 2012
Posts: 23
Thanks: 11
Thanked 0 Times in 0 Posts
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
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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



All times are GMT -4. The time now is 01:01 AM.