\<
and \>
operators are some non-standard regex operators found as extensions in some grep
implementations with or without -E
.
In most implementations, they match at the boundary between a non-word character (or the start of the subject) and a word character, and between a word character and a non-word character (or the end of the subject) respectively, word characters being alphanumeric characters or underscores.
Some grep
/regexp implementations have [[:<:]]
and [[:>:]]
for that instead and some have \b
(from perl) which matches either type of boundary.
Those that do support any of these generally also support the -w
option which matches on words.
\<Aag\>
matches inside foo-Aag
as the \<
matches inbetween -
and A
, and \>
matches between g
and the end of the subject (subject being lines for grep
).
Some grep
implementations also support \w
to match any single word character. So with those, to find any word that starts with Aa
and ends in g
, you'd use \<Aa\w*g\>
. The standard equivalent of \w
would be [[:alnum:]_]
, so \<Aa[[:alnum:]_]*g\>
would be slightly more portable. With some implementations, you may need \bAa[[:alnum:]_]*g\b
or the equivalent with [[:<:]]
and [[:>:]]
.
In standard grep
, you could use:
grep -E '(^|[^[:alnum:]_)Aa[[:alnum:]_]*g([^[:alnum:]_]|$)'
Or:
grep -x '\(.*[^[:alnum:]_]\)\{0,1\}Aa[[:alnum:]_]*g\([^[:alnum:]_].*\)\{0,1\}'
with default BREs.
If your grep
supports -P
for perl regexps, then
grep -P '\bAa\w*g\b'
Or:
grep -Pw 'Aa\w*g'
Would work. Or you could use the real thing:
perl -ne 'print if /\bAa\w*g\b/'
(though beware that by default \w
matches only on ASCII letters).
\<
and\>
are not part of POSIX standard for grep (I'd say they are GNU extensions), so the question should be tagged appropriately.