>From "man grep":
       -w, --word-regexp
              Select  only  those  lines  containing  matches  that form whole
              words.  The test is that the matching substring must  either  be
              at  the  beginning  of  the line, or preceded by a non-word con-
              stituent character.  Similarly, it must be either at the end  of
              the line or followed by a non-word constituent character.  Word-
              constituent characters are letters, digits, and the  underscore.

For example:

[EMAIL PROTECTED] root]# grep -w auto /var/log/messages | tail -n 2 -
[EMAIL PROTECTED] root]# grep -w automount /var/log/messages | tail -n 2 -
Mar 17 07:15:57 houuc8 automount[2045]: expired /home/tidwell
Mar 17 09:18:07 houuc8 automount[2685]: attempting to mount entry /software/utils

-Steve

-----Original Message-----
From: Anthony E. Greene [mailto:[EMAIL PROTECTED]
Sent: Monday, March 17, 2003 9:13 AM
To: [EMAIL PROTECTED]
Subject: Re: grep an exact match


Rigler, Steve wrote:
> Try "grep -w"

That will work if the word is on a line by itself. If there may be other 
words on the line, try this:

   grep '\Wsomething\W'

That will match the target string only if it surrounded by non-word 
characters (whitespace, puncutation, end-of-line).

Tony
-- 
Anthony E. Greene <mailto:[EMAIL PROTECTED]>
OpenPGP Key: 0x6C94239D/7B3D BD7D 7D91 1B44 BA26 C484 A42A 60DD 6C94 239D
AOL/Yahoo Chat: TonyG05   HomePage: <http://www.pobox.com/~agreene/>
Linux. The choice of a GNU generation. <http://www.linux.org/>



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list



-- 
redhat-list mailing list
unsubscribe mailto:[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to