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