Removing lines from file matching 2 strings
Clash 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?
regular-expression perl
 |Â
show 2 more comments
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?
regular-expression perl
@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 thisperl
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
 |Â
show 2 more comments
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?
regular-expression perl
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?
regular-expression perl
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 thisperl
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
 |Â
show 2 more comments
@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 thisperl
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
 |Â
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
@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