Using grep to find a string containing stars - Unix

This is a discussion on Using grep to find a string containing stars - Unix ; Hi, I encounter some difficulties finding the string "***" using the command grep under Sun's Unix Interactive (pure vintage) it seems that the star is acting as a wildcard... example : the command grep "***" file.txt reports ALL the lines ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Using grep to find a string containing stars

  1. Using grep to find a string containing stars



    Hi,

    I encounter some difficulties finding the string "***" using the command
    grep under Sun's Unix Interactive (pure vintage)

    it seems that the star is acting as a wildcard...

    example : the command grep "***" file.txt reports ALL the lines of the file.


    Any comments/advice on this ?

    Matthieu






  2. Re: Using grep to find a string containing stars

    On Fri, 25 Nov 2005 14:00:15 +0100, Matthieu Gaillet wrote:
    >
    > I encounter some difficulties finding the string "***" using the command
    > grep under Sun's Unix Interactive (pure vintage)
    >
    > it seems that the star is acting as a wildcard...
    >
    > example : the command grep "***" file.txt reports ALL the lines of the file.
    >
    >
    > Any comments/advice on this ?


    Use the escape character to prevent expansion by the shell. On linux

    grep "\*\*\*" file.txt

  3. Re: Using grep to find a string containing stars

    On Fri, 25 Nov 2005 14:00:15 +0100, Matthieu Gaillet wrote:
    [...]
    > I encounter some difficulties finding the string "***" using the command
    > grep under Sun's Unix Interactive (pure vintage)
    >
    > it seems that the star is acting as a wildcard...
    >
    > example : the command grep "***" file.txt reports ALL the lines of the file.

    [...]

    Use the "-F" flag for grep to do fixed string searches only:

    grep -F '***' < file.txt

    Or build a regexp that matches 3 stars:

    grep '\*\*\*' < file.txt

    or

    grep '[*][*][*]' < file.txt

    or

    grep -E '\*{3}' < file.txt

    --
    Stephane

  4. Re: Using grep to find a string containing stars



    Hi Bill, Bit twister and Stephane,

    Thanks to all of you. On my Unix flavour, the following string worked :

    grep "\*\*\*" myfile.txt


    Great !

    Matthieu



    "Bill Marcum" wrote in message
    news:fh2k53-gqc.ln1@don.localnet...
    > On Fri, 25 Nov 2005 08:15:09 -0600, Bit Twister
    > wrote:
    >> On Fri, 25 Nov 2005 14:00:15 +0100, Matthieu Gaillet wrote:
    >>>
    >>> I encounter some difficulties finding the string "***" using the
    >>> command
    >>> grep under Sun's Unix Interactive (pure vintage)
    >>>
    >>> it seems that the star is acting as a wildcard...
    >>>
    >>> example : the command grep "***" file.txt reports ALL the lines of the
    >>> file.
    >>>
    >>>
    >>> Any comments/advice on this ?

    >>
    >> Use the escape character to prevent expansion by the shell. On linux
    >>
    >> grep "\*\*\*" file.txt

    >
    > The quotes prevent the shell from expanding the stars. The escape
    > character prevents grep from interpreting * as a metacharacter.
    >
    >
    > --
    > To be successful, a woman has to be much better at her job than a man.
    > -- Golda Meir




+ Reply to Thread