LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep patterns (https://www.linuxquestions.org/questions/linux-newbie-8/grep-patterns-655686/)

tekmann33 07-14-2008 12:15 PM

grep patterns
 
I read the man pages for grep but I am still not sure how to do this simple task.

I want to look at log files that fall within July "Jul" AND have the string "BVCF" in them.

Is it possible to have more than one criteria in a grep command? If so, what is the correct syntax for this?

colucix 07-14-2008 12:21 PM

You can do
Code:

grep BVCF file | grep Jul

makyo 07-14-2008 01:25 PM

Hi.

Depending on your version of grep you may be able to do this:
Code:

#!/bin/bash -

# @(#) s1      Demonstrate multiple conditions for a pattern match.

echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version =o $(_eat $0 $1) grep
set -o nounset
echo

FILE=${1-data1}

echo " Data file $FILE:"
cat $FILE

echo
echo " Results:"
grep -E '(a.*b)|(b.*a)' $FILE

exit 0

Producing:
Code:

% ./s1

(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
grep (GNU grep) 2.5.1

 Data file data1:
a
b
c
cda
ab
ba
a plus b
b plus a

 Results:
ab
ba
a plus b
b plus a

In some situations you may need to use egrep -- see your man pages for details ... cheers, makyo


All times are GMT -5. The time now is 05:41 PM.