我试图提取文件夹中所有文件中以“ %%”开头的每一行,然后将这些行复制到单独的文本文件中。当前在PowerShell代码中使用此代码,但未得到任何结果。
$files = Get-ChildItem "folder" -Filter *.txt
foreach ($file in $files)
{
if ($_ -like "*%%*")
{
Set-Content "Output.txt"
}
}
我认为mklement0的使用建议是可行的Select-String
方法。除了他的答案外,您还可以将的输出通过管道传递Get-ChildItem
到,Select-String
以便整个过程成为Powershell的衬板。
像这样:
Get-ChildItem "folder" -Filter *.txt | Select-String -Pattern '^%%' | Select -ExpandProperty line | Set-Content "Output.txt"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句