Can someone please explain/help me understand the logic behind this difference between BSD grep and GNU grep? I've added carets below the matches.
$ grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ cat t1
admin:*:80:root
$ grep '\<.' t1
admin:*:80:root
^^^^^ ^^ ^^^^
versus
$ grep --version
GNU grep 2.6.3
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ cat t1
admin:*:80:root
$ grep '\<.' t1
admin:*:80:root
^ ^ ^
It seems GNU grep is getting it right and BSD grep isn't. I thought \<
is supposed to get the word boundary? Note grep '\<ad' t1
seems to get the same result in both versions, e.g.:
$ cat t2
admin:*:80:root
sadmin:*:81:root
$ grep '\<ad' t2
admin:*:80:root
^^
What gives?
Thanks in advance.
Richard
Using \>
to specify word boundary wouldn't work for BSD grep
. Try [[:<:]]
instead.
This post gives pretty useful information on word boundaries for various utilities.