0

Data

Life by cerebral flow is coming to:---1) Prolonged jumping rate---2) Small holiday course---3) Hello this world---4) Dance rock coffee---5) Therapy unproven---Choose right answer:|1,3,5|2,5|1,2,3,5   5
...
Life by cerebral flow is coming to:---1) Prolonged jumping rate---2) Small holiday course---3) Hello this world---4) Dance rock coffee---5) Therapy unproven---Choose right answer:|1.,3.,5|2,5|1,2.,3,5    5

where each line contains like that [Sentence]:---1)...(options)---n) ---[choose right ansewr]:|options| \tab [correct answer].

I want to find all those sentences which does not have a match |[1-5],[1-5]?| OR |[1-5].,[1-5]?| so allowing also |1.,| and |1,|.

My pseudocode in Perl

perl -pe '  
                 # read the file a record at a time and auto-print (-p)
    s/[0-5],[0-5]?//;    # remove those lines having the match
    s/[0-5].,[0-5]?//;    # remove those lines having the match
' file

where problem is removal of whole lines which have those matches. I can match those things but to say: remove the whole line with the match is the challenge.

How can remove those lines which have a match?

1

Use -n instead of -p:

perl -ne 'print unless /[0-5],[0-5]?|[0-5].,[0-5]?/' file

-n processes the input line by line, but doesn't automatically print each line.

I'm not sure what your goal is, so you might need to tweak the regexes, but the general approach should work.

  • How do you combine this search, for instance excluding also lines which contains the word hernia? I added 'print unless /hernia/' unsuccessfully after the first print. – Léo Léopold Hertz 준영 Jun 14 '15 at 17:40
  • 1
    You have to add it to the condition: print unless /...|hernia/ or print unless /.../ || /hernia/ – choroba Jun 14 '15 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.