【发布时间】:2022-01-07 03:01:07
【问题描述】:
(对不起,我的英语不好。)
我有两个问题:
- 问题: 我有一个 .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 文件示例: 10个, 11a, 21a, 20w, 32a, 56a, 123a,
这是所需的 .txt 文件: 11a, 21a, 20w, 32a, 56a,
我怎样才能做到?我希望你能帮助我解决这个问题。 谢谢。
【问题讨论】:
标签: powershell search design-patterns line select-string