Unix-like regex help

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
maycita
Forum Newbie
Posts: 3
Joined: Wed May 30, 2007 9:13 am

Unix-like regex help

Post 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 !!!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

grep -e "(drop table).*(?<!&)" /path/to/directory/or/file
maycita
Forum Newbie
Posts: 3
Joined: Wed May 30, 2007 9:13 am

Post by maycita »

I get the following error:

grep: illegal option -- e
Usage: grep -hblcnsviw pattern file . . .
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Which grep are you using? (GNU grep definitely has the -e option)
maycita
Forum Newbie
Posts: 3
Joined: Wed May 30, 2007 9:13 am

Post 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!
Post Reply