Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read next line?

Status
Not open for further replies.

ramam174

IS-IT--Management
Jul 28, 2004
3
GB
I have a text file:

primary1 : value;
secondary1: value;
teritiary1: value;

primary2 : value;
secondary2: value;
teritiary2: value;

While I can very well filter all the primary values, how do I get to read the immediate next line associated with each primary line?

Also, I'm interested in knowing how to read the 3rd or 'n'th line from the primary line?

Thanks in advance for any help.

- Ram
 
In the awk man page take a look at the getline function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
You could also use the NR variable to capture line number, then measure offset from that position. For example,
Code:
/^primary/ {line = NR}
NR - line == 2
This would print the 'teritiary' lines in your above example, since they're at an offset of 2 from the 'primary' lines.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top