How can I make the command grep -w show the entire line that contains the match?
I need to force pattern to match whole words, but I need to see all of the line.
Here is my command:
cat /var/log/message.log | grep -w foobar 2 Answers
If I am not mistaken, grep shows the whole line for which a match has been found.
For a specific word, I use grep directly instead of cat | grep.
grep -w "foobar" /var/log/messages.logIf you do not see any other output, it would mean that there isn't anything else on that line.
2An alternative approach (beside -w option) is to do matching whole lines by an appropriate pattern:
cat /var/log/message.log | grep -P \^\.\*foobar\.\*\$or case insensitive:
cat /var/log/message.log | grep -iP \^\.\*foobar\.\*\$One advantage here is that it could be used file indepndent, like:
xauth list | grep -iP \^\.*foobar\.\*\$