我正在嘗試從包含特定字串但不包含其他字串的除錯日志中選擇一個字串。
我想這很簡單,但我對 powershell 完全陌生。
不斷收到同樣的錯誤。“if 條件后缺少陳述句塊”
嘗試了一些變化,但無法讓它作業。
我正在嘗試的代碼是:
Get-Content -Path "~\filepath\debug.log"-Wait | Select-String "String 1" {if (notcontain (select-string "String 2"))}
提前感謝任何可以提供幫助的人!
uj5u.com熱心網友回復:
申請Select-String兩次如下:
Get-Content -Path "~\filepath\debug.log" -Wait |
Select-String "String 1" |
Select-String "String 2" -NotMatch
uj5u.com熱心網友回復:
您可以針對內容使用-match和運算子。-notmatch
這是可以解決問題的方法。
$Content = Get-Content -Path "~\filepath\debug.log" -Raw
$IsMatch = $Content -match 'String 1' -and $Content -notmatch 'String 2'
if ($IsMatch) {
Write-Host 'Yay' -ForegroundColor Cyan
} else {
Write-Host ':(' -ForegroundColor Yellow
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/439105.html
標籤:电源外壳
上一篇:合并檔案的內容,而不是一一編輯
下一篇:從CSV串列中洗掉檔案夾
