如何删除下面的匹配行:
PS /home/nicholas/powershell/regex>
PS /home/nicholas/powershell/regex> $doc = Get-Content ./foo.txt
PS /home/nicholas/powershell/regex>
PS /home/nicholas/powershell/regex> $doc
a
b
c
d
e
f
g
hmmm i j k l m
n
o
p
q
PS /home/nicholas/powershell/regex>
PS /home/nicholas/powershell/regex> $doc | Select-String 'h'
hmmm i j k l m
PS /home/nicholas/powershell/regex>
这只是一个示例,但希望遍历$doc
,删除匹配的特定行。
, 任何用"h">
看不同,返回所有其他行
感谢评论:
PS /home/nicholas/powershell/regex>
PS /home/nicholas/powershell/regex> $doc | Select-String -notmatch 'h'
a
b
c
d
e
f
g
n
o
p
q
PS /home/nicholas/powershell/regex>
似乎有效。