3 ms·
UGH! Found the problem; it simply doesn't work. Assuming the OSX awk is the same as the freebsd awk there is a very old open bug on this: awk(1) does not supp
by emmelaich 7y ago
UGH! Found the problem; it simply doesn't work. Assuming the OSX awk is the same as the freebsd awk there is a very old open bug on this:
awk(1) does not support word-boundary metacharacters
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=171725 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=171725
- jolmg 7y ago\< and \> work with GNU's awk: $ printf "fishstick\nfish\ngoldfish\n" | awk '/\<fish\>/' fish
- asicsp 7y agoGNU awk supports \< and \> for start and end of word anchors, which works for GNU grep/sed as well GNU awk also supports \y which is same as \b as well as \B for opposite (same as GNU grep/sed) Intererstingly, there's a difference between the three types of word anchors: $ # \b matches both start and end of word boundaries $ # 1st and 3rd line have space as second character $ echo 'I have 12, he has 2!' | grep -o '\b..\b' I 12 , he 2 $ # \< and \> strictly match only start and end word boundaries respectively $ echo 'I have 12, he has 2!' | grep -o '\<..\>' 12 he $ # -w ensures there are no word characters around the matching text $ # same as: grep -oP '(?<!\w)..(?!\w)' $ echo 'I have 12, he has 2!' | grep -ow '..' 12 he 2!
- emmelaich 7y agoSure, but a fair bit of the value of the tool is it's consistency across platforms. There's no point in awk if perl etc are ubiquitous and more consistent.