(提前為我的英語不好道歉。)
我有兩個問題:
- 問題:我有一個 .txt 檔案并使用 powershell 在 .txt 中搜索一個單詞:
我的代碼:
Select-String .\example.txt -pattern "myword" | select -ExpandProperty line
不錯不錯 PowerShell 在第 63 行找到了這個詞。在第 63 行之后,.txt 檔案還有 x 行,所有 (64) 行都應該被洗掉。如何才能做到這一點?
get-content .\example.txt | select-string -pattern 'myword' -notmatch | Out-File .\new_example.txt
這僅洗掉了第 63 行。但是,這應該保留,只有其余的應該被洗掉。
- 問:幾乎一樣。我搜索了兩個計數示例:12 和 33 進入 .txt Powershell 發現不是 12a 和 33a。這是正確的。Powershell 應該為它“11a 到 56a”,并清除“10a”和“123a”
.txt 檔案示例:10a、11a、21a、20w、32a、56a、123a、
這是所需的 .txt 檔案:11a, 21a, 20w, 32a, 56a,
我怎樣才能做到?我希望你能幫助我解決這些問題。謝謝。
uj5u.com熱心網友回復:
在#15136Add-From和-To引數中Select-String使用建議的原型:
@'
One
Two
myword
three
'@ -split '\r?\n' |SelectString -To myword
回報
One
Two
'10a', '11a', '21a', '20w', '32a', '56a', '123a' |
SelectString -From '(?=11a)' -To '(?<=56a)'
退貨
11a
21a
20w
32a
56a
也可以看看:
- 提取特定文本并提取
- 如何在power shell中的多條線之間進行選擇?
- 如何使用Powershell讀取txt檔案中2個特殊字符之間的行
- 無法使用 powershell 在多個關鍵字之間獲取資料
- 需要正則運算式來匹配多行,直到在公共分隔符之間找到匹配
- 從powershell中的shell命令中提取兩個關鍵字之間的多行文本
- 使用正則運算式和 powershell 提取文本塊
- 需要使用powershell從長組態檔中搜索一行
- Powershell Regex:讀取兩點之間的多行字串
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/370379.html
