Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

grep -w

Status
Not open for further replies.

ogniemi

Technical User
Nov 7, 2003
1,041
PL
Hello,

why the "grep -w" does not get only the line with "/nfs_l1"?

Code:
$ echo "host /l1 /nfs_l1 someoptions\nhost /l1/l2 /nfs_l1/l2 someoptions"|grep -w "/nfs_l1"
host /l1 /nfs_l1 someoptions
host /l1/l2 /nfs_l1/l2 someoptions
$

When I add space to "/nfs_l1 " it shows nothing:

Code:
$ echo "host /l1 /nfs_l1 someoptions\nhost /l1/l2 /nfs_l1/l2 someoptions"|grep -w "/nfs_l1 "
$

thx in advance,
r.


 
/ isn't a word constituent character.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Because it looks for "/nfs_l1 " as a whoole word space included.
If you uncote /nfs_l1 , it will ignore trailing spaces
 
The -w option is for word search, the space character is not liked because it is the delimeter character. Special charaters like hyphen and slashes may be the end of a word within a linked single concept.

eg:

low-budget

"low" is a word within the hyphenated linked single concept.

So if your grep was looking for "low" I would expect any line with "low-budget" to show.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top