Re: grep question

cbaker_at_GOODYEAR.COM
Date: 03/24/05

  • Next message: Robert Miller: "Re: grep question"
    Date:         Thu, 24 Mar 2005 13:37:21 -0500
    To: aix-l@Princeton.EDU
    
    

    Robert,

    CORRECTION:

       Think that first matched line is missing a digit. Should be
    "12345678foo", not "1345678foo".

    QUESTION:

       You are finding any line that has "foo" in the 9th through 11th space.
    Why do you need the square brackets for that. The following grep would do
    the same, no?

                 grep "^........foo" foo.txt

    CLARIFICATION:

       I assume that John wanted to get hits on any line that had "foo"
    anywhere in the line except in the first 8 characters. So he would want
    to find,

             12345678foo
             foofooedfoo

    and not find

             12345foodoggy
             1234567foo
             This foo is not a match.

    BUT, would also like to find

             123456789abcdefghijklmefoozzzzzzzzzzzz
             The word we are looking for is foo after the eighth character
             This foo did not count, but this foo will count.

    So, how do you use grep to find foo any where in the line EXCEPT in the
    first 8 characters? Obviously, sed would work better, but grep seems to
    be in question here.

    Christopher M. Baker
    Senior Technical Support Analyst
    DSE/TCO
    Goodyear Tire and Rubber Company

    =================================================
    Contains Confidential and/or Proprietary Information.
    May not be copied or disseminated without the expressed
    written consent of The Goodyear Tire & Rubber Company.
    =================================================

    Robert Miller <rmiller@SMUD.ORG>
    Sent by: IBM AIX Discussion List <aix-l@Princeton.EDU>
    03/24/2005 10:57 AM
    Please respond to
    IBM AIX Discussion List <aix-l@Princeton.EDU>

    To
    aix-l@Princeton.EDU
    cc

    Subject
    Re: grep question

    One thing you could do would be to add 8 dots to the front of your grep,
    along with the caret to match it only at the beginning of the line, so
    it'll match any 8 characters and then start matching what you actually
    want, IE:

    grep "^........[f][o][o]" foo.txt

    would find:

    1345678foo
    lasjkdlafoo
    foofoofofoo

    but not:

    asdfoo
    alskjdalksdjfoo

    --rm

    -----Original Message-----
    From: IBM AIX Discussion List [mailto:aix-l@Princeton.EDU]On Behalf Of
    John Dunn
    Sent: Thursday, March 24, 2005 7:42 AM
    To: aix-l@Princeton.EDU
    Subject: grep question

    I want to search for a lines matching a string in a file, but ignore the
    first 8 characters in each line in the search. However I do not want to
    remove the first 8 characters from the file.

    Can I do this with grep?

    John


  • Next message: Robert Miller: "Re: grep question"

    Relevant Pages

    • Re: grep question
      ... One thing you could do would be to add 8 dots to the front of your grep, along with the caret to match it only at the beginning of the line, so it'll match any 8 characters and then start matching what you actually want, IE: ... John Dunn ...
      (AIX-L)
    • Re: Help w/ matching grep and regular expressions
      ... > But with the west there, I know I want to grep it, and have grep say ... DON'T match the following characters in the. ... Be sure to play with these. ... Make a directory tree in your $HOME and ...
      (comp.unix.questions)
    • Re: grep question
      ... give you 8 characters of whatever at the beginning of the line, ... Subject: grep question ... John Dunn ... I want to search for a lines matching a string in a file, ...
      (AIX-L)
    • Re: Help w/ matching grep and regular expressions
      ... > I'm doing an assignment for a unix class, but I'm stuck on two questions. ... > and all subdirectories, recursively. ... > But with the west there, I know I want to grep it, and have grep say ... > With number four, since permissions always have ten characters, I'd want ...
      (comp.unix.questions)
    • Re: Help w/ matching grep and regular expressions
      ... > I'm doing an assignment for a unix class, but I'm stuck on two questions. ... > and all subdirectories, recursively. ... > But with the west there, I know I want to grep it, and have grep say ... > With number four, since permissions always have ten characters, I'd want to ...
      (comp.unix.questions)