Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Prepending Each Line of a LARGE Text File?

$
0
0

Hi all,

 

So, I have several large text files, upwards of 500MB or more, that I need to read and add a string to the beginning of each line in the file. It's a pretty easy task, but it seems to take a long time with the current way I'm doing it. I would love to use _FileReadToArray(), but I get memory allocation errors.

 

Is there a way to make this quicker? Here's my sample code.

 

Thank you!

AutoIt         
$sFileName = @ScriptDir & "\File.txt" $sNewFileName = @ScriptDir & "\NewFile.txt" ; If a test file doesn't exist, create one that's 10mb If FileExists($sFileName) = 0 Then     Do         FileWriteLine($sFileName, "Lots of text goes here. Lots of text goes here. Lots of text goes here. Lots of text goes here. Lots of text goes here. Lots of text goes here.")         $iSize = FileGetSize($sFileName)     Until ($iSize / 1048576) > 10 EndIf ; start a timer $iTimer = TimerInit() ; what I want to add to the beginning of each line $sPrePend = "1234" $hFile = FileOpen($sFileName, 0) While 1     $sLine = FileReadLine($hFile)     If @error = -1 Then ExitLoop; If eof, exitloop...     ; ...otherwise, prepend the line and write it to the new file     $sLine = $sPrePend & $sLine     FileWriteLine($sNewFileName, $sLine) WEnd MsgBox(0, "Time this took", TimerDiff($iTimer)) FileClose($hFile)

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>