O limite de palavras tem um efeito semelhante a -w , mas pode ser usado como parte da expressão.
‘\b’
Match the empty string at the edge of a word.
[...]
‘\<’
Match the empty string at the beginning of word.
‘\>’
Match the empty string at the end of word.
Para corresponder bar apenas quando for a palavra inteira, mas foo em qualquer lugar (incluindo palavras mais longas):
grep -E 'foo|\<bar\>'