9

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,561
  • 18
  • 86
  • 152
CodeBlue
  • 1,107
  • 8
  • 15
  • 21
  • 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

10

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,287
  • 5
  • 56
  • 64
3

You should use

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

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

enzotib
  • 50,671
  • 14
  • 120
  • 105
1

You can simply do

grep -E "MyVariable = False|MyVariable = True" FormA.frm
Kevin
  • 40,087
  • 16
  • 88
  • 112
Sachin Divekar
  • 5,772
  • 1
  • 23
  • 20
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
  • 3