Below is the code:
for i in "${x[@]}"
do
z+=$(awk '$1 == '$i' {print $2}' $file)
done
echo "${z[@]}"
It is giving following error with desire output:
awk: cmd. line:1: $1 == {print $2}
awk: cmd. line:1: ^ syntax error
I am guessing that when $1
value is not matching with $i
value it is showing this error.
Can someone tell me how this can be handle?
I tried with -v
:
z+=$(awk -v '$1 == '$i' {print $2}' $file)
but it is giving fatal:
awk: fatal: `$1 ' is not a legal variable name
x
array doesn't have an empty value in it? (x=("")
)x
array doesn't have an empty value in it.