Untitled


SUBMITTED BY: Guest

DATE: Aug. 19, 2024, 12:48 p.m.

FORMAT: Text only

SIZE: 639 Bytes

HITS: 157

  1. $sourceFilePath = "C:\path\to\your\largefile.txt"
  2. $outputDirectory = "C:\path\to\output"
  3. $linesPerFile = 1800 # Number of lines per chunk
  4. # Read the file and split it into chunks
  5. $fileContent = Get-Content $sourceFilePath
  6. $totalLines = $fileContent.Count
  7. $numberOfFiles = [math]::Ceiling($totalLines / $linesPerFile)
  8. for ($i = 0; $i -lt $numberOfFiles; $i++) {
  9. $startLine = $i * $linesPerFile
  10. $endLine = $startLine + $linesPerFile - 1
  11. if ($endLine -ge $totalLines) { $endLine = $totalLines - 1 }
  12. $fileContent[$startLine..$endLine] | Set-Content (Join-Path $outputDirectory ("Chunk_" + $i + ".txt"))
  13. }

comments powered by Disqus