I am in the process of creating a BASH shell scripts for a project at work. So the scenario is as such:
I have a file with each line entry separated by ':'
Code:
testaccount:D#%G%^V&:MeMyselfandI:memyselfandi@somesite.com:11/242012:192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5:$1360.
In parsing these strings, The only data that I need as of right now is only the row of ip address which is always the second to the last field of the line. I can successfully create my array using:
Code:
test_array=( $( cat wspasswd| awk -F ':' '/^testaccount/ {print $(NF-1) }' ) )
which produces:
Code:
echo ${#test_array[@]}
192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5
which is exactly what I want except I noticed that it is putting all of the results in only "1" index
so:
Code:
echo ${#test_array[@]}
1
echo ${test_array[0]}
192.168.1.1,192.168.1.2,192.168.1.3,192.168.1.4,192.168.1.5
I need each one of these ip address to go into its own index, so for example:
Code:
echo ${#test_array[@]}
5
echo ${test_array[0]}
192.168.1.1
echo ${test_array[1]}
192.168.1.2
and so forth
What am I missing?