Removing lines from file matching 2 strings

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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?







share|improve this question




















  • @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















up vote
0
down vote

favorite












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?







share|improve this question




















  • @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













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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?







share|improve this question












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?









share|improve this question











share|improve this question




share|improve this question










asked Oct 20 '17 at 8:21









Jim

2,771113256




2,771113256











  • @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

















  • @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
















@Inian:I want to delete the lines that contain both these strings in the line
– Jim
Oct 20 '17 at 8:28





@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




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




@SatōKatsura: Where should the parenthesis be?
– Jim
Oct 20 '17 at 8:36




3




3




perl -lne 'print unless (/foo/o and /bar/o)'
– Satō Katsura
Oct 20 '17 at 8:38




perl -lne 'print unless (/foo/o and /bar/o)'
– Satō Katsura
Oct 20 '17 at 8:38




1




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





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
















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399294%2fremoving-lines-from-file-matching-2-strings%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f399294%2fremoving-lines-from-file-matching-2-strings%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Christian Cage

How to properly install USB display driver for Fresco Logic FL2000DX on Ubuntu?