Page 1 of 1

Unix-like regex help

Posted: Wed May 30, 2007 9:22 am
by maycita
Hello everybody,

I'd like to know how is it I should write a regex in unix to match a string not followed by another string (anywhere in the line).

To be more specific, I want to find lines where "drop table" is found, but not followed anywhere in the line by the character "&".

For example,

I want to grep the line "drop table dbo.TAB_PUV_CR_0000692" in a file but not the line "drop table dbo.&1"

Thks a lot !!!

Posted: Wed May 30, 2007 9:25 am
by Jenk

Code: Select all

grep -e "(drop table).*(?<!&)" /path/to/directory/or/file

Posted: Wed May 30, 2007 9:40 am
by maycita
I get the following error:

grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . .

Posted: Wed May 30, 2007 10:17 am
by timvw
Which grep are you using? (GNU grep definitely has the -e option)

Posted: Wed May 30, 2007 10:24 am
by maycita
Now I've written:

/usr/xpg4/bin/grep -i -e "(drop table).*(?<!&)" 20070524*

I don't get any error but it doesn't match the lines it should!