I have a flat file which contains the following
INDIA USA SA NZ AUS ARG GER BRA
so there are eight columns altogether . Now I want to store the indexes of those columns only which starts with A into an array. For that I tried the following statement
awk '{for(i=1;i<=NF;i++){if($i~/^A/){set -A newArray $i}}}' testUnix.txt
when I echo the file using
echo "${newArray[*]}"
it's printing 5 6 but whenever I am trying to get the length of that array
echo ${#newArray[@]}
its length is being shown as 1 only. Should not it be 2 ? I also tried
awk '{y = 0;for(i=1;i<=NF;i++){if($i~/^A/){newArray[y] = $i ; y++}}}' testUnix.txt
but also it's producing the same result. What am I missing ?Please explain. I intend to get the desired output 2.
newArrayin awk and bash are two different entities. So when you typeecho "${newArray[*]}"its the value of bash array you are getting