BlueScreen Posted October 19, 2005 Share Posted October 19, 2005 Hi, I would like to know if there is a way to speed up a parsing action of a text file (it takes me long long time to parse around 100000 lines) Here is my simple script: $LineNum=1 $file=FileOpen("c:\blabla.txt",0) While 1 $Line=FileReadLine($file,$LineNum) $x=StringMid($line,10,4) If $x="xyz" Then exit $LineNum=$LineNum+1 ToolTip($LineNum,0,0) Wend Thanks!! Link to comment Share on other sites More sharing options...
/dev/null Posted October 19, 2005 Share Posted October 19, 2005 _FileReadToArray() Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
dabus Posted October 19, 2005 Share Posted October 19, 2005 Do as example says: $file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend FileClose($file) since a FileReadLine($file, $line) causes the $file to be read from beginning. Example just jumps to the next line. Link to comment Share on other sites More sharing options...
/dev/null Posted October 19, 2005 Share Posted October 19, 2005 Do as example says:since a FileReadLine($file, $line) causes the $file to be read from beginning. Example just jumps to the next line. That won't be any faster. _FileReadToArray() speeds up file processing quite a lot.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
BlueScreen Posted October 19, 2005 Author Share Posted October 19, 2005 Thanks! Its works a lot faster with _FileReadToArray... Link to comment Share on other sites More sharing options...
peethebee Posted October 19, 2005 Share Posted October 19, 2005 Hi! The best solution would be pure C++, I think... peethebee vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv Link to comment Share on other sites More sharing options...
/dev/null Posted October 19, 2005 Share Posted October 19, 2005 Hi!The best solution would be pure C++, I think...peethebeeSure, Assembly would be even faster, but then this would be the wrong forum to ask for help....CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
seandisanti Posted October 19, 2005 Share Posted October 19, 2005 Hi,I would like to know if there is a way to speed up a parsing action of a text file (it takes me long long time to parse around 100000 lines)Here is my simple script:$LineNum=1$file=FileOpen("c:\blabla.txt",0)While 1$Line=FileReadLine($file,$LineNum)$x=StringMid($line,10,4)If $x="xyz" Then exit$LineNum=$LineNum+1ToolTip($LineNum,0,0)WendThanks!!2 things.... first, when would a 4 character string equal "xyz" ? second... another thing you may try, which sped up my commanator (turns a file into csv file) alot would be to read the file in and then put to an array by using stringsplit(). it does pretty much the same thing as the _filereadtoarray(), just another way to skin the cat. here's my revised commanator code for example. if you wanted to compare speed of the two methods, you could add a TimerInit() and TimerDiff() to each of the codes and run for the same data, i'd be kind of interested to see if i shouldn't change my code to make use of _FileReadToArray()FileDelete("C:\output.txt") dim $contents $blah = FileRead("C:\sourceo.txt",filegetsize("C:\sourceo.txt")) $output = FileOpen("C:\output.txt",1) $contents = StringSplit($blah,@CRLF) for $z = 1 to $contents[0] $line = $contents[$z] $newline = "" for $x = 1 to StringLen($line) $achar = StringMid($line,$x,1) if $achar = " " Then if StringRight($newline,1) = "," Then ContinueLoop Else $newline = $newline & "," EndIf Else $newline = $newline & $achar EndIf Next if StringLen($newline) then FileWriteLine($output,$newline) Next FileClose($output) Link to comment Share on other sites More sharing options...
flyingboz Posted October 19, 2005 Share Posted October 19, 2005 http://www.autoitscript.com/forum/index.ph...ndpost&p=116649 Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now