Reputation: 647
I need to find all lanes which contains exact string, for example we have this input:
/home/admin fileA
/home/admin/bin fileB
and I need to find line
/home/admin fileA
I suppose I should use grep /home/admin
but it don’t work the way I want to even with -w
Upvotes: 3
Views: 2108
Reputation: 785098
Using awk:
awk '$1 == "/home/admin"' file
/home/admin fileA
EDIT: As per comment below you can use:
awk -v p=$(pwd) '$1 == p' file
Using grep
:
grep -F '/home/admin ' file
/home/admin fileA
Upvotes: 4
Reputation: 246799
Search for your term followed by a space or the end of line
grep '/home/admin\($\|[[:blank:]]\)' file
or, a little tidier
grep -E '/home/admin($|[[:blank:]])' file
grep -w
does not work because it wraps your search term in word boundary markers, and, for the 2nd line, there is a word boundary between admin
and /
Upvotes: 1
Reputation: 11782
Grep would work if you want to find anything that starts with /home/admin
but not /home/admin/
.
grep '^/home/admin[^/]' file
the [^/]
means "anything BUT a slash"
Upvotes: 1