我只想保留包含该单词的行example
并删除所有其他行。
我认为这会起作用,但它与我正在尝试做的相反:
PowerShell -Command "gci *.txt | foreach { (cat $_.FullName | ? { $_ -notlike '*example*' }) | set-content $_.FullName}"
我想以一个命令结束:
This line contains example.
This line does not.
进入这个:
This line contains example.
这似乎应该很简单,但我找不到任何答案。我发现的解决方案要么不起作用,要么相反,或者它们包含一堆我不需要做的其他事情。
干杯。
当前命令使用
-notlike
; 这意味着您不想要包含example
与您真正想要的相反的单词的行。改用-like
. 您的命令将是: