简体   繁体   中英

mawk program does not understand word border markers : "\<", "\>"

I've just noticed a new installation that Ubuntu does not have gawk installed by default.

Therefore all my awk expressions containing word border markers : "<", ">" don't work at all, example:

$ readlink -e $(which awk)
/usr/bin/mawk
$ echo "word1 Bluetooth word3" | awk '/\<Bluetooth\>/'
$

Is there way of matching words that works for both mawk and gawk ?

Depends what you want to do with the match but this might be adequate:

$ echo "word1 Bluetooth word3" | awk '/(^|[^[:alnum:]_])Bluetooth([^[:alnum:]_]|$)/'
word1 Bluetooth word3

There is no common escape sequence that means "word boundary" in all awks or even just in POSIX awks.

If that's not all you need then edit your question to better explain what you want to do with the matching string and provide sample input/output that demonstrates that usage.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM