I have huge files with size of ~3GB. These files have information section at the top as well as at the bottom, and these number of information lines differs from file to file. i.e
infostart1
infostart2
START-OF-DATA
line1
line2
...
...
...
linen
END-OF-DATA
infoend1
infoend2
etc. I am trying to create a datfile that will copy only the lines between START-OF-DATA and END-OF-DATA.
$DataStartLineNumber = (Select-String $File -Pattern 'START-OF-DATA' | Select-Object -ExpandProperty 'LineNumber')[0]
$DataEndLineNumber = (Select-String $File -Pattern 'END-OF-DATA' | Select-Object -ExpandProperty 'LineNumber')[-1]
I have tried:
Get-Content -Path $File | Select-Object -Index ($DataStartLineNumber..($DataEndLineNumber-2)) | Add-Content $Destination
but Get-Content fails due to memory usage.
I have also tried:
Get-Content -Path $File -ReadCount 10000 | Select-Object -Index ($DataStartLineNumber..$DataEndLineNumber) | Add-Content $Destination
However , this does not work as expected.
I don't want to read line by line since it takes too long. Is there any way to read chunks of data from the file and apply the filter to eliminate anything that comes before 'START-OF-DATA' and after 'END-OF-DATA'. Or copy the file as is and then delete anything that comes before 'START-OF-DATA' and after 'END-OF-DATA' in an efficient way.