Computing.Net > Forums > Unix > convert column to associative array

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

convert column to associative array

Reply to Message Icon

Name: ragu
Date: April 29, 2005 at 14:08:11 Pacific
OS: solaris 8
CPU/Ram: intel
Comment:

hi
Can any of the awk gurus around show me how to read 2 columns from a file and load them into an associative array. I have to do this from a ksh script.
e.g if i have a file with 2 columns

Stock Price
---------------------
IBM 21
INTEL 12

I should be able to get the price using a map(associative array)stock_price like:
price = stock_price[IBM]

thnx in advance
Ragu




Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: April 29, 2005 at 16:05:16 Pacific
Reply:


echo ""|nawk ' {
while (getline < "mydata" > 0)
stock_price[$1]=$2

printf("%d\n", stock_price["IBM"])
printf("%d\n", stock_price["INTEL"])

} '



0

Response Number 2
Name: ragu
Date: May 2, 2005 at 08:41:02 Pacific
Reply:

Works like a charm !
Thnx a ton Nails, really appreciate it.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: convert column to associative array

nawk associative arrays HELP! www.computing.net/answers/unix/nawk-associative-arrays-help/5823.html

Parsing file to store array variabl www.computing.net/answers/unix/parsing-file-to-store-array-variabl/8254.html

Converting HTML, PostScript or PDF to Word Doc www.computing.net/answers/unix/converting-html-postscript-or-pdf-to-word-doc/1641.html