[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep for ^ as a single word

From: Julian Foad
Subject: Re: grep for ^ as a single word
Date: Thu, 30 Mar 2006 03:12:30 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050511

Szlovencsak Attila wrote:
If I want to grep out all lines with a single '^' character as a word, I say

grep '\b\^\b' /tmp/test

but it does not give back the first two lines of the file, as expected.

This is working as intended. Grep's definition of a "word" for these purposes is not what you think it is. You can find the definition in the manual, in the description of "-w":

     -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.

- Julian

reply via email to

[Prev in Thread] Current Thread [Next in Thread]