user2915977
user2915977

Reputation: 11

how to grep only one numeric charcter

I have a file as show below and I want to grep only numeric "1" but when I will give command grep and it grep every character which is have "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

Please suggest me how can I grep only "1"

Thanks

sa

Upvotes: 0

Views: 76

Answers (2)

givanse
givanse

Reputation: 14953

You can use the patterns around the text of interest, i.e. beginning of the line and empty space.

cat tts | grep "^ 1 "

Upvotes: 0

anubhava
anubhava

Reputation: 786041

Search with word boundaries:

grep "\<1\>" file

OR else use grep -w:

grep -w "1" file

Upvotes: 2

Related Questions