Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gawk into an array question



ah, many thanks ben.  if i see you at a meeting i will gladly buy a round in your honor.  i shall try your idea now.  - eric c.

-----Original Message-----
From: Ben Eisenbraun [mailto:bene-Gk2boCrsRs1AfugRpC6u6w at public.gmane.org] 
Sent: Monday, January 26, 2009 6:04 PM
To: Eric Chadbourne
Cc: discuss-mNDKBlG2WHs at public.gmane.org
Subject: Re: gawk into an array question

Hi Eric,

> i'm trying to take a column in a text file and put it into an array.

I think you're creating the array wrong:

> -bash-3.2$ head test.csv
> catname1.dat,,catname2.dat,,catname3.dat,
> foo.txt,5,bar.txt,2,me.txt,1
> foo1.txt,10,bar1.txt,4,me1.txt,1
> foo2.txt,15,bar2.txt,5,me2.txt,2
> foo3.txt,20,bar3.txt,65,me3.txt,1
> foo4.txt,25,bar4.txt,4,me4.txt,2
> -bash-3.2$ files=`gawk -F, '{printf $1 " "}' test.csv`  #column of 
> values -bash-3.2$ declare -a list_files=$files -bash-3.2$ unset 
> list_files[0] #delete first var in array -bash-3.2$ echo $list_files

 $ head test.csv
catname1.dat,,catname2.dat,,catname3.dat,                                       
foo.txt,5,bar.txt,2,me.txt,1                                                    
foo1.txt,10,bar1.txt,4,me1.txt,1                                                
foo2.txt,15,bar2.txt,5,me2.txt,2                                                
foo3.txt,20,bar3.txt,65,me3.txt,1                                               
foo4.txt,25,bar4.txt,4,me4.txt,2   
 $ files=`awk -F, '{printf $1" "}' test.csv`  $ echo $files catname1.dat foo.txt foo1.txt foo2.txt foo3.txt foo4.txt

instead:
 $ files=(`awk -F, '{printf $1" "}' test.csv`)  $ echo $files catname1.dat  $ echo ${files[@]} catname1.dat foo.txt foo1.txt foo2.txt foo3.txt foo4.txt

-ben

--
do i contradict myself?
very well then, i contradict myself,
(i am large, i contain multitudes.)                      <walt whitman>







BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org