Reputation: 1219
I am trying to print lines where the first column contains a match with "var" using boundaries.
awk -F '|' '$1 ~ /\<$var\>/ { print $0 }'
It works as expected without trying to use a variable.
echo "18,19,20|hello world" | awk -F '|' '$1 ~ /\<18\>/ { print $0 }'
18,19,20|hello world
How can I do it using my variable?
Upvotes: 0
Views: 91
Reputation: 203522
awk -F '|' -v var="$var" '$1 ~ ("\\<"var"\\>")'
See https://www.gnu.org/software/gawk/manual/gawk.html#Computed-Regexps
Upvotes: 2