Reputation: 895
I've a file named test
# cat test
192.168.171.3 840 KB /var/opt
192.168.171.3 83 MB /var
192.168.171.3 2 KB /var/tmp
192.168.171.3 1179 KB /var/opt
192.168.171.3 65 MB /opt/var/dump
192.168.171.3 15 MB /opt/varble
192.168.171.3 3 MB /var
I want to search for entries that has only /var and not any other variations of it such as /opt/var or /var/tmp. I tried grep '^/var$' test or awk, but it doesn't work.
# grep '^/var$' test
#
# awk '/^\/var$/' test
#
Please help !
++Sorry for the pain... already got it sorted, but thanks for all your answers !++
Upvotes: 1
Views: 79
Reputation: 618
You could also use the following:
grep -w ^/var file
The -w flag will match strings that form whole words, and the ^ will force it to match the start of a line.
Upvotes: 1
Reputation: 786289
This grep command should work:
grep " /var$" file
192.168.171.3 83 MB /var
192.168.171.3 3 MB /var
Using awk:
awk '$4=="/var"' file
192.168.171.3 83 MB /var
192.168.171.3 3 MB /var
Upvotes: 2