Hello,
Can somebody please give me a snippet for the below requirement.
I want to assign the values separeted by a comma to be assigned to a dynamic array.
If I give an input (read statement) like abc1,abc2,abc3,abc4,abc5, all these strings abc* should be assigned to an array like below
export TEMP="abc1,abc2,abc3,abc4"
echo $TEMP_NODE | awk -F"," ' { arr[0]=$1 } { arr[1]=$2 } { arr[2]=$3 } { arr[3]=$4 }'
arr[0]=abc1
arr[1]=abc2
arr[2]=abc3
arr[3]=abc4
But If I give the input as abc1,abc2,.......,abc100, all these abc* strings should be assigned to an array of size 100. And if I give the input as abc1,abc2, it should assign the strings (abc1 and abc2) to an array of size 2.
With my little knowledge in Unix, I tried to get a solution by using different combinations cut,awk,sed. But I'm unable to get the desired result.
Request the Unix gurus to help me with a small shell script (sh/bash) or some thoughts to achieve this requirement.
Thanks
~Suneel