Using PowerShell to remove lines from a text file if it contains a string

前端 未结 3 1434
轮回少年
轮回少年 2020-12-06 16:12

I am trying to remove all the lines from a text file that contains a partial string using the below PowerShell code:

 Get-Content C:\\new\\temp_*.txt | Selec         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-06 16:49

    The pipe character | has a special meaning in regular expressions. a|b means "match either a or b". If you want to match a literal | character, you need to escape it:

    ... | Select-String -Pattern 'H\|159' -NotMatch | ...
    

提交回复
热议问题