Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    1

    Unanswered: grep and then count some char..

    Hi,
    i have a little problem here.
    I've written a little shell script which gets the path to some files out of a file list.txt and there is another file key.txt with keywords which should be looked for in the files of list.txt.

    That works fine, but in some of the files of list.txt there a lines like:
    ads'asdf asdfasdf 'asdf 'Asdf 'asdf 'this'Adadf
    and if the keyword this was used grepping that file, it surely will be found in that file.
    The problem is, that this is in ' ' and doenst count in this case...

    I could solve that problem by counting ' in that line, and if ' appears 2, 4, 6 ... times before this, it counts and if ' appears 3, 5, 7 .. times infront of this, this will be in ' ' and doesnt count!

    How can I do that?

  2. #2
    Join Date
    Feb 2004
    Posts
    17
    Uh, sounds nasty. I think a regular expression might help, you are likely searching for (pseudocode)
    Code:
    Zero or more times (One ' followed by zero or more characters followed by one ') followed by KEYWORD followed by zero or more characters
    While I am thinking about it, some weird hacks using awk (print all even parameters, where parameters are separated by ') might work either but you'ld have to get back the original line if you find a match.
    Pick one and I will elaborate (or you can probably find more on either topic at google).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •