Pattern matching question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern matching question
# 1  
Old 04-17-2011
Pattern matching question

Hi,

I am writing a simple log parsing system and have a question on pattern matching.

It is simply grep -v -f patterns.re /var/log/all.log

Now, I have the following in my logs
Code:
Apr 16 07:33:17 ad-font-dc1 EvntSLog: [INF] AD-FONT-DC1/NTDS ISAM (700) - "NTDS (384) NTDSA: Online defragmentation is beginning a full pass on database 'C:\WINDOWS\NTDS\ntds.dit'."

and I'm trying to match it with the following entry in patterns.re
Code:
^... .. ..:..:.. [-A-Za-z0-9_.]* [a-zA-Z]*: \[[A-Z]*\] [-A-Za-z0-9_]*/NTDS ISAM ([0-9]*) - "NTDS ([0-9]*) NTDSA: Online defragmentation is beginning a full pass on database 'C:\WINDOWS\NTDS\ntds.dit'."

And I'm not having any luck. Can a second set of eyes take a look at see what is not quite right. I suspect it has to do with the Win32 path in the logfile.

Thanks

Last edited by wpfontenot; 04-17-2011 at 10:08 PM.. Reason: Provide more information
# 2  
Old 04-17-2011
I think the problem is [-A-Za-z0-9_.]*, you have a dot within the square brackets, and that would match any characters, spaces included, so that pattern would match the whole string.

What do you want to achieve? you may describe your problem and people here might offer a better solution(Your Regex is too verbose).
# 3  
Old 04-17-2011
Quote:
Originally Posted by kevintse
What do you want to achieve? you may describe your problem and people here might offer a better solution(Your Regex is too verbose).
The regex is audit required to be that verbose - can't chance a false match that excludes something unintentionally. The only regex that is failing to match is this one - it is also the only one with a DOS filesystem path so based on that I'm fairly certain that's where my issue lies.

Last edited by wpfontenot; 04-17-2011 at 10:46 PM.. Reason: My spelling is terrible
# 4  
Old 04-18-2011
Quote:
Originally Posted by wpfontenot
Code:
\[[A-Z]*\]

The second backslash, before the right-bracket, is not necessary since the right-bracket is not a special character unless it's matching an opening left-bracket to form a bracket expression. And even when building a bracket expression, since a backslash is not special within a bracket expression, it cannot be used to quote a right bracket. Further, the \] yields an undefined sequence which can be treated differently depending on the regular expression engine implementation.

Quote:
Originally Posted by wpfontenot
Code:
C:\WINDOWS\NTDS\ntds.dit

Each backslash in that pathname, since it's intended to be taken literally, needs to be itself backslash escaped. Also, if you want to match that filename exactly, you should quote the dot before the file extension so it matches a literal dot instead of any character.
Code:
C:\\WINDOWS\\NTDS\\ntds\.dit

Regards,
Alister

---------- Post updated at 12:55 AM ---------- Previous update was at 12:51 AM ----------

Quote:
Originally Posted by kevintse
I think the problem is [-A-Za-z0-9_.]*, you have a dot within the square brackets, and that would match any characters, spaces included, so that pattern would match the whole string.
That's incorrect. A dot within a bracket expression is not special. The same goes for *, [, and \. They all lose their special meaning within a bracket expression.

Regards,
Alister

Last edited by alister; 04-18-2011 at 02:04 AM..
# 5  
Old 04-18-2011
Quote:
Originally Posted by alister
That's incorrect. A dot within a bracket expression is not special. The same goes for *, [, and \. They all lose their special meaning within a bracket expression.

Regards,
Alister
Oh, my bad.
You are right. A dot within a bracket expression only matches a dot literally.
Thank you!
# 6  
Old 04-18-2011
Thanks for the help, the quotes got it going - I had previously escaped the "\" but not the dot in the filename.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash pattern matching question

I need to check the condition of a variable before the script continues and it needs to match a specific pattern such as EPS-03-0 or PDF-02-1. The first part is a 3 or 4 letter string followed by a hyphen, then a 01,02 or 03 followed by a hyphen then a 0 or a 1. I know I could check for every... (4 Replies)
Discussion started by: stormcel
4 Replies

2. UNIX for Dummies Questions & Answers

Perl Pattern Matching Question

Hi all, I have a pattern matching problem in which i'm not sure how to attack. Here is my problem: I have a list of strings that appear in the following format: String: LE_(1234 ABC)^2^ABC^DEFG What i need to do is replace all the characters after the first ^ with blank. So the output... (2 Replies)
Discussion started by: WongSifu
2 Replies

3. Shell Programming and Scripting

pattern matching question

Hi guys I have the following case statement in my script: case $pn.$db in *?.fcp?(db)) set f ${pn} cp ;; *?.oxa?(oxa) ) set oxa $pn ;; esac Can somebody help me to understand how to interpret *?.fcp?(db)) or *?.oxa?(oxa) ? I cannot figure out how in this case pattern maching... (5 Replies)
Discussion started by: aoussenko
5 Replies

4. Shell Programming and Scripting

sed pattern matching question

I inherited a script that contains the following sed command: sed -n -e '/^.*ABCD|/p' $fileName | sed -e 's/^.*ABCD|//' | sed -e 's/|ABCD$//' > ${fileName}.tmp What I'm wondering is whether ABCD has a special pattern matching value in sed, such as a character class similar or identical to . ... (9 Replies)
Discussion started by: topmhat
9 Replies

5. Shell Programming and Scripting

pattern matching question

Hi Guys I am trying to check if the pattern "# sign followed by one or several tabs till the end of the line" exists in my file. I am using the following query: $ cat myfile | nawk '{if(/^#\t*$/) print "T"}' Unfortunately it does not return the desired output since I know for sure that the line... (4 Replies)
Discussion started by: aoussenko
4 Replies

6. Shell Programming and Scripting

Pattern matching question

Hi Guys, I am trying to setup a check for the string using an "if" statement. The valid entry is only the one which contain Numbers and Capital Alpha-Numeric characters, for example: BA6F, BA6E, BB21 etc... I am using the following "if" constract to check the input, but it fails allowing Small... (3 Replies)
Discussion started by: aoussenko
3 Replies

7. Shell Programming and Scripting

pattern matching question

Hi guys, I have a file in the following format: 4222 323K 323L D222 494 8134 A023 A024 49 812A 9871 9872 492 A961 A962 A963 491 0B77 0B78 0B79 495 0B7A 0B7B 0B7C 4949 WER9 444L 999O I need to grep the line... (5 Replies)
Discussion started by: aoussenko
5 Replies

8. Shell Programming and Scripting

SED Question: Search and Replace start of line to matching pattern

Hi guys, got a problem here with sed on the command line. If i have a string as below: online xx:wer:xcv: sdf:/asdf/http:https-asdfd How can i match the pattern "http:" and replace the start of the string to the pattern with null? I tried the following but it doesn't work: ... (3 Replies)
Discussion started by: DrivesMeCrazy
3 Replies

9. Shell Programming and Scripting

Pattern matching question

Hi guys, I have the following expression : typeset EXBYTEC_CHK=`egrep ^"+${PNUM}" /bb/data/firmexbytes.dta` can anybody please explain to me what ^"+${PNUM}" stands for in egrep statement? Thanks -A (3 Replies)
Discussion started by: aoussenko
3 Replies

10. Shell Programming and Scripting

pattern matching + perl question

i can only find the first occurance of a pattern how do i set it to loop untill all occurances have changed. #! /usr/bin/perl use POSIX; open (DFH_FILE, "./dfh") or die "Can not read file ($!)"; foreach (<DFH_FILE>) { if ($_ !~ /^#|^$/) { chomp; ... (1 Reply)
Discussion started by: Optimus_P
1 Replies
Login or Register to Ask a Question