[ale] Thanks - and another Bash script question

Bob Kruger bkruger at mindspring.com
Thu May 15 16:59:23 EDT 2003


I had the same problem here.

I have worked a way to do it that is a bit "clunky" and slow:

#check to see if the file is there.  If so, get a count of the #number of lines in the file
if [ -f $1 ]  ; then
   lc=$(wc -l < $1)
fi
ln=1
while [ $ln -le $lc ] ; do
   fl[$ln]=$(sed -n -e "$ln"p $1)
   ls[0]=$(echo ${fl[$ln]} | cut -f1 --delimiter="," )
   ls[1]=$(echo ${fl[$ln]} | cut -f2 --delimiter="," )
   ls[2]=$(echo ${fl[$ln]} | cut -f3 --delimiter="," )
   ls[3]=$(echo ${fl[$ln]} | cut -f4 --delimiter="," )
   ls[4]=$(echo ${fl[$ln]} | cut -f5 --delimiter="," | sed 's/[ ^t]*$//' )
   ls[5]=$(echo ${fl[$ln]} | cut -f6 --delimiter="," | sed 's/[ ^t]*$//' )
   ls[6]=$(echo ${fl[$ln]} | cut -f7 --delimiter="," | sed 's/[ ^t]*$//' )
   ls[7]=$(echo ${fl[$ln]} | cut -f8 --delimiter="," )
   ls[8]=$(echo ${fl[$ln]} | cut -f9 --delimiter="," )
done

Like I said, its clunky, but it works.  I was looking for something that would be a bit more streamlines and parse the data more rapidly.

Bob

-------Original Message-------
From: Geoffrey <esoteric at 3times25.net>
To: ale at ale.org
Sent: 05/15/03 03:04 PM
To: ale at ale.org
Subject: Re: [ale] Thanks - and another Bash script question

> 
> 

Fletch wrote:
>>>>>> "Bob" == Bob Kruger <bkruger at mindspring.com> writes:
> 
> Bob> If I have a line with comma based delimiters, how would I Bob>
> read that into an array, e.g.
> 
> 
> rodan:~ 609> bash -c 'IFS=",";A="This,Is A,Test";for i in $A;do echo
> $i;done' This Is A Test
> rodan:~ 610>

I did the same, but trying to stuff that into a single variable and then 
reference them as in the previous example of $ct[1]...$ct[n]  doesn't 
work.  Apparently that variable assignment does not honor IFS. ???

-- 
Until later: Geoffrey   	   	esoteric at 3times25.net

The latest, most widespread virus?  Microsoft end user agreement.
Think about it...

_______________________________________________
Ale mailing list
Ale at ale.org
<a target=_blank
href="http://www.ale.org/mailman/listinfo/ale">http://www.ale.org/mailman/listinfo/ale</a>
> 
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale





More information about the Ale mailing list