[ale] bash question [array]
Ken Alexander
kenry at alexandertech.biz
Fri Jul 13 11:35:19 EDT 2007
I'm not a guru, but I think this is what you want ...
declare -a anarray
declare -i x
filename=temp1
exec 3<$filename
x=1
while read line <&3; do
anarray[$x]=$line
echo ${anarray[$x]}
firstfield[$x]=${line:0:4}
echo ${firstfield[$x]}
x+=1
done
exec 3>&- # close the file
On Fri, 2007-07-13 at 10:42 -0400, Dr. Brian J. Dowd wrote:
> Any bash gurus out there?
> trying to parse substrings from lines, read from a file, into
> variables of an array...
>
> declare -a anarray
> filename=temp1
> exec 3<$filename
> let x=1
>
> while read line <&3; do
> anarray[x]=$line
> echo ${anarray[$x]} # this works and prints the whole line
> firstfield[x]={$line:0:4}; echo $firstfield[x] # this just prints
> the string " [x] "
> let "x += 1"
> done
>
> exec 3>&- # close the file
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ale
mailing list