Re: grep: match i to j occurences of abc

From: Kurt J. Lanza (klanza_at_rcn.com)
Date: 08/30/03

  • Next message: Erik Max Francis: "Re: grep: match i to j occurences of abc"
    Date: Sat, 30 Aug 2003 16:55:54 -0400
    
    

    Penna Elabi wrote:

    > I have file test:
    >
    > abc
    > abc abc abc
    > abc abc abc abc
    >
    > How do I print with grep lines where abc occurs at least 3 times but
    > no more than 4 times (i.e. second and third line):
    >
    > abc abc abc
    > abc abc abc abc
    >
    > I have read man grep, and it says:
    >
    > \{i,j\}
    > matches any number of occurrences of the character matched by
    > the BRE from i to j, inclusive.
    >
    > So, I tried these:
    >
    > grep abc\{3,5\} test
    > grep 'abc\{3,5\}' test
    > grep 'abc'\{3,5\} test
    >
    > But they don't work.

    Grep is the wrong tool. You are trying to match between 3 and 5
    occurrences of the letter 'c'. That's why the man page refers to a
    'character'. (Duh.) Try 'awk' instead. I'm much to lazy to figure out
    the details.


  • Next message: Erik Max Francis: "Re: grep: match i to j occurences of abc"