Click to See Complete Forum and Search --> : [RESOLVED] [BASH] need help with awk to array


NikosNL
April 30th, 2008, 11:13 AM
I am building a program, and I need some variables from a file to an array.

This is working:
bt ~ # var1=$(awk 'BEGIN {FS=", "}/user/{ print $1 }' qsutf8.txt)
bt ~ # echo $var1
usertest1 usertest2 usertest3

but how can i program it so this works: ?
bt ~ # echo array[0]
usertest1
bt ~ # echo array[1]
usertest2
bt ~ # echo array[2]
usertest3

Does someone know how to do that.
I tried a lot of thinks but none were working.

Thanks for looking at this post!

Nikos

PeejAvery
April 30th, 2008, 12:51 PM
[ moved ]

NikosNL
May 1st, 2008, 12:56 PM
Thanks!

It is solved!

PeejAvery
May 1st, 2008, 01:00 PM
For the help of possible viewers...why don't you post your solution?

NikosNL
May 2nd, 2008, 09:09 AM
ok

Just did this:

var1=($(awk 'BEGIN {FS=", "}/user/{
print " "
print $1
print " " }' qsutf8.txt))

the print can probably written shorter :P