【问题标题】:Delete lines containing specific character in text file删除文本文件中包含特定字符的行
【发布时间】:2016-10-03 19:43:51
【问题描述】:

如何使用 PowerShell 删除文本文件中包含特定字符的行?

输入文件示例:

12314+000000 00000000
20 300 1238238948023
A+A+000000 00000000
20 500 1238238948023

输出文件示例:

20 300 1238238948023 20 500 1238238948023

因此它将删除包含+ 或特定字符或单词的行。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    最简单的方法是使用新文件向其中写入数据:

    Get-Content "D:\test.txt" | Where-Object {$_ -notmatch '\+'} | Set-Content "D:\out.txt"
    

    这将给出:

    20 300 1238238948023
    20 500 1238238948023
    

    out.txt

    这用于answerthis

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-03
      • 2011-09-05
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 2012-07-02
      • 2018-03-15
      相关资源
      最近更新 更多