An awk script provides me as output "name1 1" "name2 2" "name3 3"... "name11 11"
.
I want to store these values in an array, without executing the awk script again and again for each value extraction.
I looked up array declaration at GNU Reference and name=(value1 value2 … )
should work for my use case.
Tried out various techniques
#!/bin/bash
line='"name1 1" "name2 2" "name3 3"'
arr=($line)
echo ${arr[2]}
#output - "name2
arr2=("name1 1" "name2 2" "name3 3")
echo ${arr2[2]}
#output - name3 3
arr3=(`echo '"name1 1" "name2 2" "name3 3"'`)
echo ${arr3[2]}
#output - "name2
I don't know how to use the second method of the above, in combination with awk
.
Help would be appreciated! And if possible reasoning for this weird behaviour