gawk into an array question

Eric Chadbourne EChadbourne-3av5VAs6qClGBRGhe+f61g at public.gmane.org
Mon Jan 26 18:08:12 EST 2009


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>






More information about the Discuss mailing list