How can I use findstr with newline regular expression

后端 未结 4 1294
天涯浪人
天涯浪人 2020-12-21 14:51

I\'m on windows dos prompt. I have log file which contains log like:

Timestamp: Order received for Item No. 26551
Timestamp: Exception: OutOfRangeException
T         


        
4条回答
  •  暖寄归人
    2020-12-21 15:14

    If you are on Vista or Windows 7 (or if you install it manually on XP), you can use PowerShell for this:

    $resultlist = new-object System.Collections.Specialized.StringCollection
    $regex = [regex] '(?m)^.*Exception.*\r\n.*Item No\. (\d+)'
    $match = $regex.Match($subject)
    while ($match.Success) {
        $resultlist.Add($match.Groups[1].Value) | out-null
        $match = $match.NextMatch()
    } 
    

    $resultlist will then contain a list of all item numbers that follow a line with Exception in it.

提交回复
热议问题