I would like to grep for two statements in a file at a time.?

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

Update:

Do we have and operator in UNIX?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Use egrep:

    egrep "expression1|expression2"

    or

    grep -E "expression1|expression2"

  • 1 decade ago

    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

    Source(s): Bart G. Colbert UNIX Sys Admin, Programmer http://www.intencities.net
Still have questions? Get your answers by asking now.