1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Linux grep pattern search?

Discussion in 'Software' started by N4N01D, 13 Feb 2006.

  1. N4N01D

    N4N01D What's a Dremel?

    Joined:
    29 Apr 2004
    Posts:
    467
    Likes Received:
    0
    Hi, im trying to do a pattern search and getting nowhere.

    The wordd "lightweight" includes the same four characters (namely ight) repeated. How many such words are there (any four character are repeated).

    Anyone any ideas how to do this with grep (nothing else)?

    TIA
    N4N01D
     
  2. trigger

    trigger Procrastinator

    Joined:
    22 Mar 2004
    Posts:
    1,106
    Likes Received:
    37
    I'm not sure I understand what you are trying to do, but you can use regexps with grep, so that may help, although I've no experience with them myself, everytime I look at them they seem to be a black art by themselves!
     
  3. N4N01D

    N4N01D What's a Dremel?

    Joined:
    29 Apr 2004
    Posts:
    467
    Likes Received:
    0
    ok, the letters "ight" can be found once in the word "light" and twice in the word "lightweight" what i am trying to do is find how many words in the file "words" have a 4 character repeating pattern such as "ight" and others, this make it any clearer?
     
  4. woodshop

    woodshop UnSeenly

    Joined:
    14 Oct 2003
    Posts:
    1,408
    Likes Received:
    8
    you can find 'ight' or any other "known" pattern in words easly enough...

    however to find an unknown 4 letter pattern that appears in a min of x words then return the # of words with it.... Thats would be out of the scope of grep i think..

    Only way i know, that could play out, would be to read in each word from the file then use a combo of length() and substr() to read out 4 letter segments in 1 letter incriments out of the input word. then search the entire file for that 4 letter pattern.. do this till you run out of input words..

    you could speed that up a bit by maintaing an allready searched DB. but it ould still take some time.

    BTW the lenght() and substr() are perl.. I Just like Perl when it comes to having to do string stuff.
     
  5. N4N01D

    N4N01D What's a Dremel?

    Joined:
    29 Apr 2004
    Posts:
    467
    Likes Received:
    0
    lol, na it can be done with grep... i just asked my lecturer and he said something about using () but that it doesnt matter that i wasnt able to get it most people cant :)
     
Tags:

Share This Page