Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    34
    Rep Power
    9
    Originally Posted by ghostdog74
    use awk
    Code:
    awk -F"," '{
      for(i=1;i<=NF;i++){   if ( $i~/S1|S2|S3/ ) ++d   }
      if ( d == 3) {   print $0  }
      d=0  
    }' file
    Hi,
    This script isn't worked d. You got any better suggestion?
    I just try to run it. The output result mostly all are out of the range that I desired.
    Hope you got better suggestion.
    Still thanks a lot for your help
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    Ahh, I was hoping that would not be the case!
    awk may well be the best way to go as you can do multiple operations per pass through the file. I'll have a sit and a think.
    In the meantime, a quick and dirty way might be (broken up to make clearer):

    Code:
    grep -v -e S10 -e S11 -e S12 YourInputFile > IntemediaryFile
    grep S1 IntermdediaryFile | grep S2 | grep S3 > OutputFile
    Nasty as it uses grep multiple times, plus you may find rogue lines being passed forward (assuming that S15 might be a valid entry - the S1 test would match that).
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #18
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    34
    Rep Power
    9
    Originally Posted by SimonJM
    Ahh, I was hoping that would not be the case!
    awk may well be the best way to go as you can do multiple operations per pass through the file. I'll have a sit and a think.
    In the meantime, a quick and dirty way might be (broken up to make clearer):

    Code:
    grep -v -e S10 -e S11 -e S12 YourInputFile > IntemediaryFile
    grep S1 IntermdediaryFile | grep S2 | grep S3 > OutputFile
    Nasty as it uses grep multiple times, plus you may find rogue lines being passed forward (assuming that S15 might be a valid entry - the S1 test would match that).
    Hi,
    the above command line is better than the previous one...
    No matter continuous or discontinuous, it also will take as consideration. But when I run through the file, it still will take the line like S2 and S3 only as consideration (which is not what I desired).
    or you got any better suggestion by using awk?
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo