awk match whole word
If you want to pass "ABC" as a variable instead of hardcoding it, use the matching operator:
awk -v word=ABC '$0 ~ "[^[:alpha:]]" word "[^[:alpha:]]"'
With gawk (other awks too?) you can use \<
and \>
to denote word boundaries, where a word is a sequence of letters, digits and underscore (I believe), so this will work for your example:
awk '/\<ABC\>/'
Use \y
for word boundary, e.g.
awk '/\yABC\y/'
See https://www.gnu.org/software/gawk/manual/html_node/GNU-Regexp-Operators.html for more details.
Figured it out - was having problems due to a typo
awk '/[^[:alpha:]]ABC[^[:alpha:]]/'