Home > Back-end >  GREP only if whole string
GREP only if whole string

Time:12-02

Here is the list.txt file:

001 Linux000

002 Linux001

003 Linux002

cat list.txt | grep 002 returns:

002 Linux001

003 Linux002

But I need to get only lines where is 002, not Linux002.

002 Linux001

CodePudding user response:

Taking word boundaries (\b) into account with GNU grep:

grep '\b002\b' list.txt

CodePudding user response:

Does this grep work?

$ grep '\<002\>' input_file
002 Linux001
  • Related