How to search for an exact word with the grep command

Asked

Viewed 1,549 times

2

Well, whenever I use the grep command he looks for a word that contains the desired word + anything, how can I make him understand that I just want that word and nothing else? ex:

ps aux|grep bc

instead of him looking for

...... bcache
...... bclink
...... bc
......
......

he seeks only the word bc

......bc

1 answer

10


Use the option --word-regexp or simply -w, for example:

ps aux | grep -w bc

The above parameter will return only the line that contains the informed word (and not only a part of it) preceded by nonconstituent characters (letters, numbers and underscore).

  • I vote mine, and you still win medal ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.