l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
June 2: Social gathering
Next Installfest:
Latest News:
May. 19: LUGOD special elections
Page last updated:
2007 May 03 15:56

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] creating a lookup table in awk
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] creating a lookup table in awk


awk does simulate multi-dimensional arrays (using the form col[dl,pit,sensor]) so you could use:
col[1,1,1] = 4
col[1,1,2] = 5
col[1,2,1] = 8

You could then read the data using:
while(getline <"dataloggerfile_d" > 0) {
for(p = 1; p <= numpits; p++)
for(s = 1; s <= numsensors; s++)



At 12:41 PM 5/3/2007, you wrote:

Hi everyone,

I have a rather interesting problem, that i would like to solve with awk or
bash scripting - but if all else fails then I will switch to python.

here is the idea:

i have a set of files, each with 30 columns - coming from a set of 10 data
loggers. each file represents the output from a single datalogger. the
ordering of the columns is consistant, and maps to a soil-pit id and moisture
probe id. I need to create a look-up table to index ids to column numbers.
Then, looping over the dimensions of the look-up table would allow me to
process the file line-by line, column-by column accordingly:

do bash or awk support these type of data structures?

this is how i would envision it in something like python / php:

# a multi-dimensional hash for each datalogger:
# referencing the sensors assigned to a pit
# and the row number in which the sensor values exist in the output file
sensor_1 => 4
sensor_2 => 5
sensor_3 => 6
sensor_4 => 7
sensor_1 => 8
sensor_2 => 9
sensor_3 => 10
sensor_4 => 11
sensor_5 => 12

# the logic of the program would be :
iterate over the pits in the datalogger hash
        iterate over the sensors in each pit hash
                lookup the column number for each sensor
                do cool stuff

any ideas ? or should I just stick with python for this?


Dylan Beaudette
Soils and Biogeochemistry Graduate Group
University of California at Davis
vox-tech mailing list
vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Appahost Applications
For a significant contribution towards our projector, and a generous donation to allow us to continue meeting at the Davis Library.