0

我有一个如下所示的文件,我只想 grep 数字“1”,但是当我给出命令 grep 时,它会 grep 每个具有“1”的字符

 0 turks-g         DD-Production-Server Incremental-Bac pls-i085-g      10/23/2013 18:04:53
 1 pls-w099-g      Production-PCI-Serve Incremental-Bac pls-i097-g      10/23/2013 18:05:36
 0 longjawed-g     DD-Production-Server Incremental-Bac pls-i086-g      10/23/2013 18:09:09
 1 pls-i085-g      NetBackup-Servers    Incremental-Bac pls-i085-g      10/23/2013 18:09:28

猎户座 # cat tts |grep "1"

0 turks-g DD-生产-服务器增量-Bac pls-i085-g 10/23/2013 18:04:53 1 pls-w099-g 生产-PCI-服务增量-Bac pls-i097-g 10/23/ 2013 18:05:36 0 longjawed-g DD-生产-服务器增量-Bac pls-i086-g 10/23/2013 18:09:09 1 pls-i085-g NetBackup-服务器增量-Bac pls-i085-g 2013 年 10 月 23 日 18:09:28

猎户座 # cat tts |grep '1'

0 turks-g DD-生产-服务器增量-Bac pls-i085-g 10/23/2013 18:04:53 1 pls-w099-g 生产-PCI-服务增量-Bac pls-i097-g 10/23/ 2013 18:05:36 0 longjawed-g DD-生产-服务器增量-Bac pls-i086-g 10/23/2013 18:09:09 1 pls-i085-g NetBackup-服务器增量-Bac pls-i085-g 2013 年 10 月 23 日 18:09:28

请建议我如何仅 grep “1”

谢谢

4

2 回答 2

2

使用单词边界搜索:

grep "\<1\>" file

或者使用grep -w

grep -w "1" file
于 2013-10-24T13:49:16.083 回答
0

您可以在感兴趣的文本周围使用模式,即行首和空白区域。

cat tts | grep "^ 1 "
于 2013-10-24T13:53:25.940 回答