我有一个文本文件,它看起来像这样:滤波部分,包括起点和终点的线 - PowerShell的
Data I'm NOT looking for
More data that doesn't matter
Even more data that I don't
&Start/Finally the data I'm looking for
&Data/More data that I need
&Stop/I need this too
&Start/Second batch of data I need
&Data/I need this too
&Stop/Okay now I'm done
Ending that I don't need
这里是输出需要什么:
File1.txt
&Start/Finally the data I'm looking for
&Data/More data that I need
&Stop/I need this too
FILE2.TXT
&Start/Second batch of data I need
&Data/I need this too
&Stop/Okay now I'm done
我需要为文件夹中的所有文件(有时会出现,这将需要过滤多个文件)的文件名可以增加这样做:恩。 File1.txt,File2.txt,File3.txt。
这是我已经没有运气尝试:
ForEach-Object{
$text -join "`n" -split '(?ms)(?=^&START)' -match '^&START' |
Out-File B:\PowerShell\$filename}
谢谢!
完美地工作。谢谢!!! – red2015