Reputation: 41
cmd: cat test.txt | grep pin
results: prints all lines containing pin
I want to now only grep for words containing pin. What is the command to so that?
Thanks!
All, thank you for your comments. I am using the Git Bash (version 1.9.4). The grep in this shell do not have the -o option. There is a -w option. I tried: grep -w 'pin' test.txt but it returns nothing.
Anyone using Git Bash to solve this issue?
Thank you all.
Upvotes: 4
Views: 17415
Reputation: 1823
You can use -w option.
$ cat test
pin
PIN
somepin
aping
spinx
$ grep pin test
pin
somepin
aping
spinx
$ grep -w pin test
pin
$
Upvotes: 0
Reputation: 2281
Assuming your file is called test.txt
, you can do:
grep -o '\S*pin\S*' test.txt
The -o
flag will print only the matching words on the line, as opposed to the whole line.
Upvotes: 1