In my variable pattern there is square parentheses ( abc[0]
), but awk is unable to find pattern. If I change my pattern from abc[0]
to abc_0
, then it works.
echo "test_var=$test_var, test_var_1=$test_var_1"
# Output - test_var=abc[0], test_var_1=abc[0]
echo "$test_var" | awk -v variable="$test_var_1" '$0 ~ variable {print $variable}'
# "NO OUTPUT"
echo "test_var=$test_var, test_var_1=$test_var_1"
# test_var=abc_0, test_var_1=abc_0
echo "$test_var" | awk -v variable="$test_var_1" '$0 ~ variable {print $variable}'
# Here Output is abc_0
How to find pattern variable which has square parenthesis by awk command?