GREP 仅当整个字符串

GREP only if whole string

这是 list.txt 文件:

001 Linux000

002 Linux001

003 Linux002

cat list.txt | grep 002 returns:

002 Linux001

003 Linux002

但我只需要获取 002 所在的行,而不是 Linux002。

002 Linux001

使用 GNU grep 考虑单词边界 (\b):

grep '\b002\b' list.txt

这个grep有效吗?

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