Truncate half of very large file

Solution 1:

There are many possibilities for splitting and joining a large file.

If you would accept a third-party free utility, then you could use HJ Split, or GSplit, but there exist many others.

If you would like to keep the file as whole and at the same time compress it into chunks, you may use 7Zip, where on the Add to Archive screen you have the field Split to volumes, specifying the number of bytes for each chunk and some more options.

If you prefer a PowerShell script, you may use Split-File.ps1 which contains the functions of split by byte size and join:

Split-File "BigFile.dat" 10000000
dir BigFile??.dat | Join-File Rebuild.dat

If you are using the Windows Subsystem for Linux (WSL), you may use the Linux commands of split and cat.

If all you want is copy a part of the file, you may use this PowerShell one-liner that uses the commands Get-Content and Set-Content :

$file = (Get-Content log.txt)[<from-line..<to-line>] | Set-Content logpart.txt

Get-Content also has the -Tail parameter that you asked about, hopefully in a more efficient manner.