【发布时间】:2016-10-25 11:56:23
【问题描述】:
我有一个如下所示的文本文件:
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
输出需要如下:
文件1.txt
&Start/Finally the data I'm looking for
&Data/More data that I need
&Stop/I need this too
文件2.txt
&Start/Second batch of data I need
&Data/I need this too
&Stop/Okay now I'm done
我需要对文件夹中的每个文件执行此操作(有时会有多个文件需要过滤。)文件名可以递增:例如。文件1.txt、文件2.txt、文件3.txt。
这是我没有运气的尝试:
ForEach-Object{
$text -join "`n" -split '(?ms)(?=^&START)' -match '^&START' |
Out-File B:\PowerShell\$filename}
谢谢!
【问题讨论】: