I'm trying to search through a file using awk, by looping over elements of a bash array. This is what I'm currently doing
myarray[1] = 441
myarray[2] = 123
for i in "${myarray[@]}"
do
awk '{if ($4 == '"$i"') print $0}' myfile.txt > newfile.txt
done
Is it possible to access elements of a bash array in awk in this way?
"'"$i"'"instead of just'"$i"').awkis still not "accessing shell variables". Rather, you are using the value of a shell variable in a string that you pass to awk. The value of$iis expanded by the shell before theawkcommand is executed."${myarray[@]}'"which could be what's messing you up.