Reputation: 65
I'm new to powershell and i need help on a really simple script.
I've got a big log file (100 M) which i want to parse and return errors and warning messages.
Here is the format of the log file:
2013-04-18T10:38:04,110 INFO [00002865] 30:toto.toto - WARNING: La variable sousdomn existe déjà pour le fichier WORK.RGPDROITS.
The aim is to check the bold value (which could be WARN ; ERROR ; INFO) and return lines where the bold value is "WARN" or "ERROR"
Here is the script tested on the WARN value:
$logfile = "C:\log\logfile.log"
cat $logfile |
Select-String -pattern WARN -CaseSensitive|
select -expand line |
foreach {
write-output $_.
}
Unfortunately, it also returns "INFO" messages when they contain the string WARNING:
2013-04-18T10:38:04,141 INFO [00002865] 30:toto.toto - WARNING: Référence symbolique apparente NBPERA non traitée.
I think, i need to use something like the -clike option?
Upvotes: 0
Views: 458
Reputation: 53
In above code pattern WARN will catch string "WARNING" so you need to add extra space \s in regular expression to avoid WARNING so correct code will be
$logfile = "C:\log\logfile.log";
cat $logfile |
Select-String -pattern WARN\s -CaseSensitive|
select -expand line |
foreach {
write-output $_.
}
Upvotes: 0
Reputation: 19828
Replace your pattern with:
Select-String -Pattern "\sWARN\s"
\s
is for space. You can use a regular expression in pattern string
Upvotes: 1