1846634 Members
1886 Online
110256 Solutions
New Discussion

Re: grep command

 
SOLVED
Go to solution
Chern Jian Leaw
Regular Advisor

grep command

HI,

Is there a way exclude several patterns all at once from a file?

I have the a file of the form:
#cat fileA
FILE OWNER SIZE
--------------------
f1 ken 17
f2 john 17
f3 peter 17

I would like to ignore lines beginning with FILE and with the pattern "------", simultaneously

I tried the followiu:
#grep -v "FILE" "--" fileA > temp
grep: 0652-033 Cannot open --.

#grep -vv "FILE" "--" fileA > temp
grep: 0652-033 Cannot open --.

#grep -v "FILE" -v "--" fileA > temp
grep: 0652-033 Cannot open --.

could someone show me how I could exclude several patterns from different lines in a file, simultenously i.e in 1 command?

Thanks.
11 REPLIES 11
Justo Exposito
Esteemed Contributor
Solution

Re: grep command

Hi,

Try this:

grep -v -e "FILE" -e "--" fileA > temp

Regards,

Justo.
Help is a Beatiful word
RAC_1
Honored Contributor

Re: grep command

grep -Ev "FILE|---" your_file
There is no substitute to HARDWORK
Frank Slootweg
Honored Contributor

Re: grep command

grep -v -e '^FILE' -e '^----' fileA >temp

Instead of multiple "-e" options, you can also put the patterns in a file and use that file "-f pattern_file".
Ollie R
Respected Contributor

Re: grep command

Hi,
You need to use the following:
grep -v -e '' -e ''

Cheers,


Ollie.
To err is human but to not award points is unforgivable
Frank Slootweg
Honored Contributor

Re: grep command

Four responses in two minutes, not bad! :-)

[No points for this one please.]
Ollie R
Respected Contributor

Re: grep command

No points??? Meany! 8Ob
To err is human but to not award points is unforgivable
Frank Slootweg
Honored Contributor

Re: grep command

I meant no points for the response in which I said that, i.e. my 10:52 AM one.

Of course the other responses, including mine :-), deserve points.

[No points for *T*H*I*S* response please! :-)]
Robin Wakefield
Honored Contributor

Re: grep command

...or even:

Create a file containing your ignore strings, e.g.

fileA.ignore contains:
FILE
----


then:

grep -v -f fileA.ignore fileA

Rgds, Robin.
Chern Jian Leaw
Regular Advisor

Re: grep command

robin,

I tried what you've suggested. But the pattern is fileA is still not ignored.

#cat pattern
FILE
------

#grep -v pattern fileA > temp

The file temp still contains patterns beginning with FILE and ---

Could you show me how I could have such patterns included into the file?

Thanks.
Pete Randall
Outstanding Contributor

Re: grep command

Robin's answer should work - I think you left out the "-f" that should have appeared before "pattern".

Pete

Pete
John Dvorchak
Honored Contributor

Re: grep command

Or you could simply use:

egrep -v 'FILE|---' fileA

good luck
If it has wheels or a skirt, you can't afford it.