Operating System - HP-UX
1753549 Members
5421 Online
108795 Solutions
New Discussion юеВ

grep for more than 1 value

 
SOLVED
Go to solution
Muktha
Frequent Advisor

grep for more than 1 value

Hi all,

I need to grep for more than 1 value and neglect all those lines.
I tried as below:-
cat File_name | grep -v value1

But i can't use grep -v for neglecting more than 1 value.Is there any way to resolve this problem?
Please help me to find out the solution.

Thanks & regards
Muktha
10 REPLIES 10
Robert-Jan Goossens_1
Honored Contributor

Re: grep for more than 1 value

Hi,

Try egrep

# egrep -e value1 -e value2 File_name

Regards,
Robert-Jan
Prashanth Waugh
Esteemed Contributor
Solution

Re: grep for more than 1 value

Hi Muktha,

Pls try below command
#egrep -v 'good|okay' inventory

here inventory is file name
we r neglecting good and okay word from inventry file

Regards
Prashant
For success, attitude is equally as important as ability
Ivan Krastev
Honored Contributor

Re: grep for more than 1 value

Use file with patterns:
cat 1.txt
1
3
5

cat test.txt
1
2
3
4
5
6
7

grep -v -f 1.txt test.txt
2
4
6
7


regards,
ivan

Muktha
Frequent Advisor

Re: grep for more than 1 value

Hi Robert-Jan , Prashant ,

Thanks for your quick respose.

Regards
Muktha
Muktha
Frequent Advisor

Re: grep for more than 1 value

Thank you very much Prashant .
It worked out.

Regards
Muktha
Muktha
Frequent Advisor

Re: grep for more than 1 value

Thanks ivan ,

You gave new idea..

Regards
Muktha
James R. Ferguson
Acclaimed Contributor

Re: grep for more than 1 value

Hi:

First, don;t add a useless 'cat' to open and read the file, piping that output to 'grep'. That's a wasted process and wasted I/O.

You can do :

# grep -v -e value1 -e value2 -e value3 File_name

(or):

# grep -vE "value1|value2|value3" File_name

Regards!

...JRF...
Muktha
Frequent Advisor

Re: grep for more than 1 value

I did not notice that.
Anyway thanks for the guidance.
Muktha
Frequent Advisor

Re: grep for more than 1 value

Thanks to all for helping me..