我有一個文本文件,它看起來像這樣:濾波部分,包括起點和終點的線 - 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