Jon L
Jon L

Reputation: 1

grep with regex in middle of line

I have a log file entry that looks like this:

04/21 15:22:56 Information [jrpp-42] - Error Executing Database Query. Stored procedure 'dbo.get_discount' not found. Specify owner.objectname or use sp_help to check whether the object exists (sp_help may produce lots of output).
The error occurred on line 67. The specific sequence of files included or processed is: /default.cfm || Location -- 10.8.79.7 || Browser -- || Querystring -- sshealth=1 || Referer --

I am trying to grep specifically for this part:

Error Executing Database Query. Stored procedure 'dbo.get_discount' not found.

However the part after dbo. is variable. It's not always get_discount. I'm trying to find the regex expression that will account for that and then still include the "' not found" string.

I can do this in two parts but I'm wondering if there is a regular expression that would work. Thanks.

e.g grep "Error Executing Database Query. Stored procedure 'dbo.[REGEX]' not found." filename.log

Upvotes: 0

Views: 1489

Answers (2)

ghostdog74
ghostdog74

Reputation: 342263

You can use grep or you can use awk. With awk you have the advantage to do programming upon finding your string.

awk "/Stored procedure 'dbo.[^']*' not found/" file

Upvotes: 0

DigitalRoss
DigitalRoss

Reputation: 146053

grep "Stored procedure 'dbo.[^']*' not found" filename.log

Upvotes: 2

Related Questions