我有一个文件如下所示,我想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
orion #cat tts | 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
orion #cat tts | 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
请建议我如何才能只使用“1”
谢谢
SA
答案 0 :(得分:2)
使用字边界搜索:
grep "\<1\>" file
或者使用grep -w
:
grep -w "1" file
答案 1 :(得分:0)
您可以使用感兴趣文本周围的图案,即线条的开头和空白区域。
cat tts | grep "^ 1 "