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

use column as variable

Status
Not open for further replies.

rhnaeco

Technical User
Aug 11, 2005
45
Hi, I have columns of data which are measurements of current flow in the water column. The instrument returns data from above the water column, which is data I want to remove (retain only data in the water, not any noise).

my datafile (headers):

ensemble, depth, 1, 2, 3, 4,... 34, 35, 36, 37

the numbers are bin numbers; bin 1 is on the seabed and bin 37 is above the water column. I want to delete all data above the waterline. Normally i'd just print $1-$34, but as the tide changes water level it is not always the same bin.

I can convert 'depth' to 'bin number' so my question is:
Can i use a column as a variable to control how many columns i print in total?

so:
ensemble, depth, bin/variable, bin 1, bin 2......
23453, 33.4, 33, 1, 2, 3, 4...31, 32 (stop)

print $1, £2, $3, $4 to $35

35265, 29.8, 29, 1, 2, 3, 4...27, 28 (stop)

print $1, $2, $3, $4 to $31

I hope someone can help

thanks

R
 
A starting point:
Code:
for(i=1;i<=(1+$3),++i)printf "%s,",$i;print $(2+$3)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, but i still can't get it to work. My layout is slightly different now (bin, ensemble, data....) so i've used:
for(i=1;i<=(1+$1);++i)printf "%s,",$i;print $(2+$1)
but all i get is extra blank space at the end and nothing removed. Can you offer further help?

I've included the first two line of actual data and the output.

INPUT (52 columns):
32,4780,496,510,541,503,513,828,920,979,951,882,942,960,887,974,958,930,
953,1125,1169,1381,1362,1377,1318,1261,1243,1196,1137,1176,1113,1122,937,
976,659,762,800,748,915,802,789,823,875,937,988,1028,875,871,909,798,829,
676

OUTPUT:
32,4780,496,510,541,503,513,828,920,979,951,882,942,960,887,974,958,930,
953,1125,1169,1381,1362,1377,1318,1261,1243,1196,1137,1176,1113,1122,937,
976,659,762,800,748,915,802,789,823,875,937,988,1028,875,871,909,798,829,
676,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

thanks

R
 
Did you set the field separator to comma ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hehe - no. Thanks PHV.

i'm SO rusty with awk!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top