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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extracting data by row number

Status
Not open for further replies.

baer

Technical User
Jul 15, 2001
4
US
Hello,

I am looking to extract data from a program output that repeats tables several times. I am interested in the final set of data. I have unsuccessfully been able to think of a clever way to cut my dataset to only include the final portion of the report. Conceptually, I want to find the max (record number) for \TABLE SB-3. NETWORK SEGMENT NO 3\, then extract part of the data by using this record number and the end of the file. From this point, I can further divide the data.

The table header looks like the following. ( There is a bunch of data in between the headers.)


TABLE SB-3. NETWORK SEGMENT NO 3
TABLE SB-3. NETWORK SEGMENT NO 2
TABLE SB-3. NETWORK SEGMENT NO 1
TABLE SB-3. NETWORK SEGMENT NO 3
TABLE SB-3. NETWORK SEGMENT NO 2
TABLE SB-3. NETWORK SEGMENT NO 1

Any suggestions would be appreciated.

Thanks
 
This may do what you want.

BEGIN {
while ((getline < &quot;-&quot;) > 0) {
num++
if (substr($0,1,5) == &quot;TABLE&quot; && $6 == 3) hldnr = num
}
close(&quot;-&quot;)
num = 0
while ((getline < &quot;-&quot;) > 0) {
num++
if (num >= hldnr) {
print
}
}
exit
}

Run it by entering awk -f script-above.awk < data-file

Not all versions of awk allow you to read from stdin using the &quot;-&quot; syntax. You could get around this by hardcoding the name of your input file in place of the -

Let me know if this does what you want.

CaKiwi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top