我使用select字符串来搜索文件中的错误。是否可以像grep一样排除搜索模式。例如:
grep ERR* | grep -v "ERR-10"
select-string -path logerror.txt -pattern "ERR"logerror.txt
OK
ERR-10
OK
OK
ERR-20
OK
OK
ERR-10
ERR-00我想要得到所有的ERR行,但不是ERR-00和ERR-10
发布于 2016-08-25 21:06:39
我想你可以在这里使用Where-Object。
Write-Output @"
OK
ERR-10
OK
OK
ERR-20
OK
OK
ERR-10
ERR-00
"@ > "C:\temp\log.txt"
# Option 1.
Get-Content "C:\temp\log.txt" | Where-Object { $_ -Match "ERR*"} | Where-Object { $_ -NotMatch "ERR-[01]0"}
# Option 2.
Get-Content "C:\temp\log.txt" | Where-Object { $_ -Match "ERR*" -and $_ -NotMatch "ERR-[01]0"}发布于 2017-11-01 02:43:55
为此,我使用了"-NotMatch“参数
PS C:\>Get-Content .\some.txt
1
2
3
4
5
PS C:\>Get-Content .\some.txt | Select-String -Pattern "3" -NotMatch
1
2
4
5对于您的情况,答案是:
Get-Content .\logerror.txt | Select-String -Pattern "ERR*" | Select-String -Pattern "ERR-[01]0" -NotMatchhttps://stackoverflow.com/questions/39126832
复制相似问题