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!

multilple line record, join 1

Status
Not open for further replies.

baer

Technical User
Jul 15, 2001
4
US
Hello,

I am attempting to extract sediment data for a hydrology model and I am running into difficulties.

The following is a sample of the data.

INFLOW
CLAY :17.8666 :
SILT :3.77577 :3.42650 :23.8600 :18.5159 :
SAND :4.33102 :2.46574 :22.4748 :21.7308 :

RIVER MILE = 140.000
CLAY :17.8661 :
SILT :3.77571 :3.42635 :23.8559 :18.5046 :
SAND :4.33102 :2.46574 :22.4718 :21.7273 :

RIVER MILE = 80.000
CLAY :17.8661 :
SILT :3.77571 :3.42635 :23.8559 :18.5046 :
SAND :4.33102 :2.46574 :22.4718 :21.7265 :
----

Initially, I would like get a row that prints the river mile, then the 9 values for the types of sediment. For example the first row would appear as 0, 17.8666, 3.77577 , 3.42650, 23.8600, 18.5159, 4.33102, 2.46574, 22.4748,21.7308 . The first record "INFLOW" is located at RIVER MILE = 0 and I need to account for that.

To this end I have unsuccessfully tried to surpress the line return. I have also tried to designate the FS=":" and the record seperator to be "". However, the output continues to show the different values from different seperated by rows.

Any suggestions are appreciated.

Thank,
 
Hi Baer,

Here's my suggestion:

BEGIN { FS = ":" }
/INFLOW/ {mile = 0}
/^CLAY/ {a0 = $2}
/^SILT/ {a1 = $2;a2 = $3; a3 = $4; a4 = $5}
/^SAND/ {a5 = $2;a6 = $3; a7 = $4; a8 = $5}
/^RIVER/ {
print mile "," a0 "," a1 "," a2 "," a3 "," a4
"," a5 "," a6 "," a7 "," a8;
mile = substr($0,13) + 0
}
END {
print mile "," a0 "," a1 "," a2 "," a3 "," a4
"," a5 "," a6 "," a7 "," a8;
}

Hope this helps

CaKiwi
 
Thank you very much. This is very close to what I need. However; my data set has several inflow points. (For example, picture the dataset from above repeated.) When this script reaches another INFLOW entry, the last RIVER MILE entry is not extracted. I have looked over the script, and I cannot see why this is happening.

This can be demonstrated by copying the data from above twice and running the script.

Thanks,
 
I think you need to change the /INFLOW/ line to be

/^INFLOW/ { if ( mile > 0)
print mile "," a0 "," a1 "," a2 "," a3 "," a4
"," a5 "," a6 "," a7 "," a8;
mile = 0 }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top