Hello,
I have been stuck on this aspect of loading a comma delimited file into an array. I thought i had the syntax right, but my commands are not working the way I want them to. Basically my cut command is splitting the file up by spaces and commas. I want the cut command to ignore white spaces. I have googled, used the man pages, and tried other solutions ie (awk, sed), but I am still stuck on this aspect.
comma delimited file:
23232321223,11100,N/A,Hey You There,N/A,N/A,Wed Jul 26 09:02:26 2006
#script to split it into an array
SPArray=( "${SPArray[@]}" `cat $dnNum"SPTest.txt" | cut -d, -f2`)
SPArray=( "${SPArray[@]}" `cat $dnNum"SPTest.txt" | cut -d, -f3`)
SPArray=( "${SPArray[@]}" `cat $dnNum"SPTest.txt" | cut -d, -f4`)
len=${#SPArray[*]}
#Displaying the contents of the array
i=0
while [ $i -lt $len ]; do
echo "$i: ${SPArray[$i]}"
i=$((i+1))
done
Actual output:
0: 11100
1: N/A
2: Hey
3: You
4: There
the output I wish i had:
0: 11100
1: N/A
2: Hey You There