How to combine two grep statements and display their results together?
Clash Royale CLAN TAG#URR8PPP
up vote
8
down vote
favorite
Suppose I do
grep "MyVariable = False" FormA.frm
... result1
grep "MyVariable = True" FormA.frm
... result2
How to write the grep command so that I can say something like
grep "MyVariable = False" OR "MyVariable = True" FormA.frm
grep
add a comment |Â
up vote
8
down vote
favorite
Suppose I do
grep "MyVariable = False" FormA.frm
... result1
grep "MyVariable = True" FormA.frm
... result2
How to write the grep command so that I can say something like
grep "MyVariable = False" OR "MyVariable = True" FormA.frm
grep
You want to test whether a line containsVar1 = False
ANDVar2 = True
? Or whether a file containsVar1 = False
ANDVar2 = True
? Or something else? An example would help.
â Mikel
Mar 28 '12 at 15:40
I used AND by mistake. I meant "OR".
â CodeBlue
Mar 28 '12 at 15:43
add a comment |Â
up vote
8
down vote
favorite
up vote
8
down vote
favorite
Suppose I do
grep "MyVariable = False" FormA.frm
... result1
grep "MyVariable = True" FormA.frm
... result2
How to write the grep command so that I can say something like
grep "MyVariable = False" OR "MyVariable = True" FormA.frm
grep
Suppose I do
grep "MyVariable = False" FormA.frm
... result1
grep "MyVariable = True" FormA.frm
... result2
How to write the grep command so that I can say something like
grep "MyVariable = False" OR "MyVariable = True" FormA.frm
grep
grep
edited 17 mins ago
Sparhawk
8,60363589
8,60363589
asked Mar 28 '12 at 15:20
CodeBlue
50731020
50731020
You want to test whether a line containsVar1 = False
ANDVar2 = True
? Or whether a file containsVar1 = False
ANDVar2 = True
? Or something else? An example would help.
â Mikel
Mar 28 '12 at 15:40
I used AND by mistake. I meant "OR".
â CodeBlue
Mar 28 '12 at 15:43
add a comment |Â
You want to test whether a line containsVar1 = False
ANDVar2 = True
? Or whether a file containsVar1 = False
ANDVar2 = True
? Or something else? An example would help.
â Mikel
Mar 28 '12 at 15:40
I used AND by mistake. I meant "OR".
â CodeBlue
Mar 28 '12 at 15:43
You want to test whether a line contains
Var1 = False
AND Var2 = True
? Or whether a file contains Var1 = False
AND Var2 = True
? Or something else? An example would help.â Mikel
Mar 28 '12 at 15:40
You want to test whether a line contains
Var1 = False
AND Var2 = True
? Or whether a file contains Var1 = False
AND Var2 = True
? Or something else? An example would help.â Mikel
Mar 28 '12 at 15:40
I used AND by mistake. I meant "OR".
â CodeBlue
Mar 28 '12 at 15:43
I used AND by mistake. I meant "OR".
â CodeBlue
Mar 28 '12 at 15:43
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
10
down vote
accepted
What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".
Use "extended grep" and the OR operator (|
).
grep -E 'MyVariable = False|MyVariable = True' FormA.frm
1
Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
â CodeBlue
Mar 28 '12 at 15:40
Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
â CodeBlue
Mar 28 '12 at 15:41
1
@CodeBlue: you should get used to this: almost everything is case sensitive in Unix
â enzotib
Mar 28 '12 at 16:00
Ok thanks @enzotib . I come from a Windows background.
â CodeBlue
Mar 28 '12 at 16:03
It also works withegrep
(which I use) instead ofgrep -E
which is the more canonical.
â Arcege
Mar 28 '12 at 16:58
add a comment |Â
up vote
3
down vote
You should use
grep "MyVariable = (False|True)" FormA.frm
where the |
sequence mean an alternative, and the delimiters (
and )
are for grouping.
Yup, this also works, although it is a bit confusing to me. Thanks.
â CodeBlue
Mar 28 '12 at 15:47
add a comment |Â
up vote
1
down vote
You can simply do
grep -E "MyVariable = False|MyVariable = True" FormA.frm
add a comment |Â
up vote
1
down vote
To answer in another way than what has already been said...
You can also specify several matches to grep, by specifying the -e
option several times
% grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
... result1
... result2
It would be nice if you would write your answer using the text from the question rather than making up your own example.
â G-Man
Jun 13 at 14:40
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".
Use "extended grep" and the OR operator (|
).
grep -E 'MyVariable = False|MyVariable = True' FormA.frm
1
Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
â CodeBlue
Mar 28 '12 at 15:40
Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
â CodeBlue
Mar 28 '12 at 15:41
1
@CodeBlue: you should get used to this: almost everything is case sensitive in Unix
â enzotib
Mar 28 '12 at 16:00
Ok thanks @enzotib . I come from a Windows background.
â CodeBlue
Mar 28 '12 at 16:03
It also works withegrep
(which I use) instead ofgrep -E
which is the more canonical.
â Arcege
Mar 28 '12 at 16:58
add a comment |Â
up vote
10
down vote
accepted
What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".
Use "extended grep" and the OR operator (|
).
grep -E 'MyVariable = False|MyVariable = True' FormA.frm
1
Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
â CodeBlue
Mar 28 '12 at 15:40
Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
â CodeBlue
Mar 28 '12 at 15:41
1
@CodeBlue: you should get used to this: almost everything is case sensitive in Unix
â enzotib
Mar 28 '12 at 16:00
Ok thanks @enzotib . I come from a Windows background.
â CodeBlue
Mar 28 '12 at 16:03
It also works withegrep
(which I use) instead ofgrep -E
which is the more canonical.
â Arcege
Mar 28 '12 at 16:58
add a comment |Â
up vote
10
down vote
accepted
up vote
10
down vote
accepted
What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".
Use "extended grep" and the OR operator (|
).
grep -E 'MyVariable = False|MyVariable = True' FormA.frm
What you really want is "OR", not "AND". If "AND" is used, then logically, you'll get no lines (unless the line is something like "MyVariable = False...MyVariable = True".
Use "extended grep" and the OR operator (|
).
grep -E 'MyVariable = False|MyVariable = True' FormA.frm
answered Mar 28 '12 at 15:31
Arcege
16.5k33956
16.5k33956
1
Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
â CodeBlue
Mar 28 '12 at 15:40
Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
â CodeBlue
Mar 28 '12 at 15:41
1
@CodeBlue: you should get used to this: almost everything is case sensitive in Unix
â enzotib
Mar 28 '12 at 16:00
Ok thanks @enzotib . I come from a Windows background.
â CodeBlue
Mar 28 '12 at 16:03
It also works withegrep
(which I use) instead ofgrep -E
which is the more canonical.
â Arcege
Mar 28 '12 at 16:58
add a comment |Â
1
Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
â CodeBlue
Mar 28 '12 at 15:40
Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
â CodeBlue
Mar 28 '12 at 15:41
1
@CodeBlue: you should get used to this: almost everything is case sensitive in Unix
â enzotib
Mar 28 '12 at 16:00
Ok thanks @enzotib . I come from a Windows background.
â CodeBlue
Mar 28 '12 at 16:03
It also works withegrep
(which I use) instead ofgrep -E
which is the more canonical.
â Arcege
Mar 28 '12 at 16:58
1
1
Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
â CodeBlue
Mar 28 '12 at 15:40
Yes, you're right. I wanted OR but incorrectly specified AND. Thanks.
â CodeBlue
Mar 28 '12 at 15:40
Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
â CodeBlue
Mar 28 '12 at 15:41
Incidentally, I noticed this works only with an uppercase "E" and not a lowercase "e". So grep arguments are case sensitive I suppose.
â CodeBlue
Mar 28 '12 at 15:41
1
1
@CodeBlue: you should get used to this: almost everything is case sensitive in Unix
â enzotib
Mar 28 '12 at 16:00
@CodeBlue: you should get used to this: almost everything is case sensitive in Unix
â enzotib
Mar 28 '12 at 16:00
Ok thanks @enzotib . I come from a Windows background.
â CodeBlue
Mar 28 '12 at 16:03
Ok thanks @enzotib . I come from a Windows background.
â CodeBlue
Mar 28 '12 at 16:03
It also works with
egrep
(which I use) instead of grep -E
which is the more canonical.â Arcege
Mar 28 '12 at 16:58
It also works with
egrep
(which I use) instead of grep -E
which is the more canonical.â Arcege
Mar 28 '12 at 16:58
add a comment |Â
up vote
3
down vote
You should use
grep "MyVariable = (False|True)" FormA.frm
where the |
sequence mean an alternative, and the delimiters (
and )
are for grouping.
Yup, this also works, although it is a bit confusing to me. Thanks.
â CodeBlue
Mar 28 '12 at 15:47
add a comment |Â
up vote
3
down vote
You should use
grep "MyVariable = (False|True)" FormA.frm
where the |
sequence mean an alternative, and the delimiters (
and )
are for grouping.
Yup, this also works, although it is a bit confusing to me. Thanks.
â CodeBlue
Mar 28 '12 at 15:47
add a comment |Â
up vote
3
down vote
up vote
3
down vote
You should use
grep "MyVariable = (False|True)" FormA.frm
where the |
sequence mean an alternative, and the delimiters (
and )
are for grouping.
You should use
grep "MyVariable = (False|True)" FormA.frm
where the |
sequence mean an alternative, and the delimiters (
and )
are for grouping.
answered Mar 28 '12 at 15:29
enzotib
32.8k710292
32.8k710292
Yup, this also works, although it is a bit confusing to me. Thanks.
â CodeBlue
Mar 28 '12 at 15:47
add a comment |Â
Yup, this also works, although it is a bit confusing to me. Thanks.
â CodeBlue
Mar 28 '12 at 15:47
Yup, this also works, although it is a bit confusing to me. Thanks.
â CodeBlue
Mar 28 '12 at 15:47
Yup, this also works, although it is a bit confusing to me. Thanks.
â CodeBlue
Mar 28 '12 at 15:47
add a comment |Â
up vote
1
down vote
You can simply do
grep -E "MyVariable = False|MyVariable = True" FormA.frm
add a comment |Â
up vote
1
down vote
You can simply do
grep -E "MyVariable = False|MyVariable = True" FormA.frm
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can simply do
grep -E "MyVariable = False|MyVariable = True" FormA.frm
You can simply do
grep -E "MyVariable = False|MyVariable = True" FormA.frm
edited Mar 28 '12 at 15:34
Kevin
26.2k105897
26.2k105897
answered Mar 28 '12 at 15:30
Sachin Divekar
3,7781619
3,7781619
add a comment |Â
add a comment |Â
up vote
1
down vote
To answer in another way than what has already been said...
You can also specify several matches to grep, by specifying the -e
option several times
% grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
... result1
... result2
It would be nice if you would write your answer using the text from the question rather than making up your own example.
â G-Man
Jun 13 at 14:40
add a comment |Â
up vote
1
down vote
To answer in another way than what has already been said...
You can also specify several matches to grep, by specifying the -e
option several times
% grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
... result1
... result2
It would be nice if you would write your answer using the text from the question rather than making up your own example.
â G-Man
Jun 13 at 14:40
add a comment |Â
up vote
1
down vote
up vote
1
down vote
To answer in another way than what has already been said...
You can also specify several matches to grep, by specifying the -e
option several times
% grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
... result1
... result2
To answer in another way than what has already been said...
You can also specify several matches to grep, by specifying the -e
option several times
% grep -e "MyVariable = True" -e "MyVariable = False" FormA.frm
... result1
... result2
edited Jun 13 at 14:48
answered Jun 13 at 14:28
Vince
1213
1213
It would be nice if you would write your answer using the text from the question rather than making up your own example.
â G-Man
Jun 13 at 14:40
add a comment |Â
It would be nice if you would write your answer using the text from the question rather than making up your own example.
â G-Man
Jun 13 at 14:40
It would be nice if you would write your answer using the text from the question rather than making up your own example.
â G-Man
Jun 13 at 14:40
It would be nice if you would write your answer using the text from the question rather than making up your own example.
â G-Man
Jun 13 at 14:40
add a comment |Â
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%2f35241%2fhow-to-combine-two-grep-statements-and-display-their-results-together%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
You want to test whether a line contains
Var1 = False
ANDVar2 = True
? Or whether a file containsVar1 = False
ANDVar2 = True
? Or something else? An example would help.â Mikel
Mar 28 '12 at 15:40
I used AND by mistake. I meant "OR".
â CodeBlue
Mar 28 '12 at 15:43