The awk command does not work as expected when the bash variable is used internally

advertisements

I tried to use bash variable inside awk by creating a variable in awk command as below. but it does not work it seems

b=hi
$ echo "hihello" |awk -v myvar=$b -F"$0~myvar" '{print $2}'

Actual Output is :

<empty / nothing printed >

Expected output is :

hello


Why don't you do this:

b=hi ; echo "hihello" | awk -F"$b" '{print $2}'
hello