10

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
Sparhawk
  • 19,941
CodeBlue
  • 1,117
  • 8
  • 15
  • 22
  • 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

4 Answers4

11

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
Arcege
  • 22,536
3

You should use

grep "MyVariable = \(False\|True\)" FormA.frm

where the \| sequence mean an alternative, and the delimiters \( and \) are for grouping.

enzotib
  • 51,661
1

You can simply do

grep -E "MyVariable = False|MyVariable = True" FormA.frm
Kevin
  • 40,767
1

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
Vince
  • 131