1834608 Members
3089 Online
110069 Solutions
New Discussion

grep problem

 
SOLVED
Go to solution
thebeatlesguru
Regular Advisor

grep problem

how can i use grep to find two different things on the same time.
for example i wanna find "TOM" and "JIM" on the same time.
hihi
6 REPLIES 6
Steve Steel
Honored Contributor

Re: grep problem

Hi


Not really meant to do this but
script with parameters
file tom jim

file=$1
n1=$2
n2=$3
cat $file|while read line
do
echo $line|grep $n1
echo $line|grep $n2
done


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Robin Wakefield
Honored Contributor
Solution

Re: grep problem

Hi,

You have two ways with grep:

# grep -i -e tom -e jim filename

# grep -i -E 'tom|jim' filename

"-i" makes the search case-insensitive.

Rgds, Robin.
Steven Sim Kok Leong
Honored Contributor

Re: grep problem

Hi,

This will do the trick.

# grep -e TOM -e JIM file_to_grep

Hope this helps. Regards.

Steven Sim Kok Leong
federico_3
Honored Contributor

Re: grep problem



do:

cat file | grep -e "TOM"-e "JIM"


ciao
Federico
Andreas Voss
Honored Contributor

Re: grep problem

Hi,

try it with egrep ie:

egrep '(TOM|JIM)'

Regards
Tim D Fulford
Honored Contributor

Re: grep problem

1 - grep -e "TOM" -e "JIM"
2 - (my preferred) egrep "TOM|JIM"

rgds

Tim
-