English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I would like to grep for two statements in a file at a time.
i.e.,

I want to find out if my file contains both the statements in it or not.

Thanks in advance,
Swapna

2006-12-24 21:37:53 · 2 answers · asked by sk 1 in Computers & Internet Programming & Design

Do we have and operator in UNIX?

2006-12-24 21:39:47 · update #1

2 answers

Use egrep:

egrep "expression1|expression2"

or

grep -E "expression1|expression2"

2006-12-24 21:58:28 · answer #1 · answered by Vesselin Bontchev 6 · 0 0

I am assuming you are in a UNIX shell.

you can you a if statement with test to find multiple results.

if [ $( $(cat mylife | grep wordone) | wc -l ) -ne 0 ] ; then
if [ $( $(cat mylife | grep wordtwo) | wc -l ) -ne 0 ] ; then DO THIS; fi
fi

2006-12-24 22:10:34 · answer #2 · answered by bgcolbe 2 · 0 0

fedest.com, questions and answers