problems egreging for a '(0)' string

Hi,

I'm trying to egreg for a couple strings whcih are (0) and SYSTEM. The problem is the syntax for egreg is:

egreg "(string1|string2)"

With my basic knowledge of UNIX I don't know how to include '(0)' within "(string1|string2)" apart from trying to use single quotes which doesn't work, i.e. "('(0)')".

I reckon this must be eary to resolve but need some expert advice.

Can anyone help?

Gareth

why dont u try as such,

egrep '(0)|system' filename

Thanks, I've tried this and it doesn't work. This provides the same output as:

egrep -v "0|SYSTEM"

i dont understand,

can u plz post the sample input and output.

Madhan's command works absolutly fine.. here is how it works

$ more tmp1
hai it is the begining
this is test (0) for unix.com
also to test SYSTEM for the same
this is the end of the file

$ egrep '(0)|SYSTEM' tmp1
this is test (0) for unix.com
also to test SYSTEM for the same

can you tell me what was the error you got ?

I don't know if egrep works the same everywhere, but: why not use grep instead?

grep -e "0" -e "SYSTEM"

will find every line containing either "0" or "SYSTEM" - at least on my AIX system.

bakunin

Whilst you're seeing what you think is the correct output that's because it's actually greping for 0 and SYSTEM

# cat tmp
hai it is the begining
this is test (0) for unix.com
also to test SYSTEM for the same
this is the end of the file
this is test 0 for unix.com

If I want to exclude lines including (0) using your syntax I get the following result:

# egrep -v '(0)|SYSTEM' tmp
hai it is the begining
this is the end of the file

Line 5 should not have been removed if the pattern is (0)

You have to escape the '(' and the ')'. Like this:

$ cat test
hai it is the begining
this is test (0) for unix.com
also to test SYSTEM for the same
this is the end of the file
this is test 0 for unix.com
$ egrep -v '\(0\)|SYSTEM' test
hai it is the begining
this is the end of the file
this is test 0 for unix.com

Here is some food for thought. I wanted to do this without the quotes, so I fiddled around and got this:

How are

egrep -v '\(0\)|SYSTEM' test

and

 egrep -v \\\(0\\\)\|SYSTEM test

the same?

Ran the two on FreeBSD 4.6 under ksh. Check the output:

$ cat test
hai it is the begining
this is test (0) for unix.com
also to test SYSTEM for the same
this is the end of the file
this is test 0 for unix.com
$ egrep -v '\(0\)|SYSTEM' test
hai it is the begining
this is the end of the file
this is test 0 for unix.com
$ egrep -v \\\(0\\\)\|SYSTEM test
hai it is the begining
this is the end of the file
this is test 0 for unix.com

I dont need the explaination about having to escape the '|'. Its the multiple \s.

Thanks, that's sorted it, I new it'd be summat simple just didn't know how to escape the brackets.

Many thanks for everyone's help