我只想保留包含单词的行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
. 您的命令将是:
PowerShell -Command "gci *.txt | foreach { (cat $_.FullName | ? { $_ -like '*example*' }) | set-content $_.FullName}"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句