我想創建PowerShell腳本,將通過一些Sql Server腳本的日誌文件,並調查存在的單詞「錯誤」。我這樣做:PowerShell正則表達式錯誤,除了從DBCC警告
Get-Content $log | Select-String "error" -quiet #returns true/false
或 Get-Content $ log |選擇字符串「錯誤」 #returns線與「錯誤」
問題是,我的日誌文件中還包含來自DBCC類似的警告:
26: DBCC execution completed. If DBCC printed error messages, contact your system administrator.
24: DBCC execution completed. If DBCC printed error messages, contact your system administrator.
如何列出只是「錯誤」行,但不「如果DBCC打印錯誤消息」? 我嘗試了諸如:
Get-Content "d:\InsightMasterESF\logs\currentlog.txt" | Select-String -pattern "(error)(?!If DBCC printed error messages)"
但我不知道正則表達式的模式很好。
正則表達式的第一條規則是「知道你的數據」。如果您需要正則表達式的幫助,我們需要確切知道我們需要匹配的數據是什麼樣的。 – mjolinor