0

I am trying to remove lines in a file that contain 2 strings.
I am using:

perl -i.tmp -ne "print unless /$STRING_A/ and /$STRING_B/" /foo/bar/file.txt  

The result is that all lines from the file containing $STRING_A are deleted regardless if $STRING_B is also in the same line.
What is the problem here? How can I fix this?

  • @Inian:I want to delete the lines that contain both these strings in the line – Jim Oct 20 '17 at 8:28
  • Have you consider adding parentheses? and has a very low priority. – Satō Katsura Oct 20 '17 at 8:33
  • @SatōKatsura: Where should the parenthesis be? – Jim Oct 20 '17 at 8:36
  • 3
    perl -lne 'print unless (/foo/o and /bar/o)' – Satō Katsura Oct 20 '17 at 8:38
  • 1
    I tested this perl command with and without parenthesis and it worked just fine. @Jim, could you provide an example where it didn't work? – cesarv Oct 20 '17 at 9:52

Your Answer

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

Browse other questions tagged or ask your own question.