Alitai Posted October 4, 2019 Share Posted October 4, 2019 Hi Everyone I made a Script which removes all numbers or chars higher then 2 (3 and more) from a block of 5. Now there is the Problem. The Script is slow. Sooo slow in fact that it takes ever to run. I am not a programmer and i happy that it runs and works. Does anyone know how this Script can be made faster (Yes, there is a sleep in it which makes it slower but i think this is not the big Problem)? Many Thanks Regards Alitai Quote #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Array.au3> #include <File.au3> local $aFile _FileReadToArray(@ScriptDir &"\more.txt", $aFile) $sFileName2 = @ScriptDir &"\less.txt" $hFilehandle2 = FileOpen($sFileName2, $FO_OVERWRITE) Local $sOriginal Local $i $str = 0 While ($str <> 3000000) $str += 1 $sOriginal = $aFile[$str] While 1 Sleep(5) $si = 0 $sOne = StringMid($sOriginal, $i+1, 1) $sTwo = StringMid($sOriginal, $i+2, 1) $sThree = StringMid($sOriginal, $i+3, 1) $sFour = StringMid($sOriginal, $i+4, 1) $sFive = StringMid($sOriginal, $i+5, 1) If $sOne = $sTwo Then If $sTwo = $sThree Then ExitLoop EndIf Else ;Nothing EndIf If $sTwo = $sThree Then If $sThree = $sFour Then ExitLoop EndIf Else ;Nothing EndIf If $sThree = $sFour Then If $sFour = $sFive Then ExitLoop EndIf Else ;Nothing EndIf If $sOne = $sTwo Then If $sTwo = $sFour Then ExitLoop EndIf Else ;Nothing EndIf If $sTwo = $sThree Then If $sThree = $sFive Then ExitLoop EndIf Else ;Nothing EndIf If $sOne = $sThree Then If $sThree = $sFour Then ExitLoop EndIf Else ;Nothing EndIf If $sTwo = $sFour Then If $sFour = $sFive Then ExitLoop EndIf Else ;Nothing EndIf If $sOne = $sThree Then If $sThree = $sFive Then ExitLoop EndIf Else ;Nothing EndIf If $sOne = $sTwo Then If $sTwo = $sFive Then ExitLoop EndIf Else ;Nothing EndIf If $sOne = $sFour Then If $sFour = $sFive Then ExitLoop EndIf Else FileWrite($hFilehandle2, $sOriginal & @CRLF) ExitLoop EndIf FileWrite($hFilehandle2, $sOriginal & @CRLF) ExitLoop WEnd WEnd Link to comment Share on other sites More sharing options...
Alitai Posted October 4, 2019 Author Share Posted October 4, 2019 What i forget to write it takes only the lines which have 2 or less chars and numbers. Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted October 4, 2019 Share Posted October 4, 2019 @Alitai Could you please post an example of the file you are reading? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
jchd Posted October 4, 2019 Share Posted October 4, 2019 Your request is hard to understand. As FrancescoDiMuro just said, post a sample of input file and the expected output, along with a clear reason for removing unwanted lines. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Alitai Posted October 4, 2019 Author Share Posted October 4, 2019 1 minute ago, FrancescoDiMuro said: @Alitai Could you please post an example of the file you are reading? Wow, thanks for your answer first. Yes, sure: Quote 9999V 9999B 9999N 9999M 99992 99993 99994 99995 99996 99997 99998 99999 QQW4N QQW4M QQW42 QQW43 QQW44 QQW45 QQW46 QQW47 QQW48 QVRNG QVRNF QVRND QVRNY QVRNX QVRNC QVRNV QVRNB QVRNN QVRNM QVRN2 YDRDK YDRDJ YDRDH YDRDG YDRDF YDRDD YDRDY YDRDX YDRDC YDRDV YDRDB YDRDN YDRDM YDRD2 YDRD3 YDRD4 YDRD5 YDRD6 YDRD7 YDRD8 YDRD9 YDRYQ YDRYW QWQQQ QWQQW QWQQR QWQQT QWQQP QWQQK QWQQJ QWQQH QWQQG QWQQF QWQQD QWQQY QWQQX QWQQC QWQQV QWQQB QWQQN QWQQM QWQQ2 QWQQ3 QWQQ4 QWQQ5 QWQQ6 QWQQ7 QWQQ8 QWQQ9 QWQWQ QWQWW QWQWR QWQWT QWQWP QWQWK QWQWJ QWQWH QWQWG Link to comment Share on other sites More sharing options...
jchd Posted October 4, 2019 Share Posted October 4, 2019 And with this input, what output do you expect? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Alitai Posted October 4, 2019 Author Share Posted October 4, 2019 3 minutes ago, jchd said: And with this input, what output do you expect? It removes all lines which have 3 or more of the same chars or numbers in it. Output: Quote QQW4N QQW4M QQW42 QQW43 QQW44 QQW45 QQW46 QQW47 QQW48 QVRNG QVRNF QVRND QVRNY QVRNX QVRNC QVRNV QVRNB QVRNN QVRNM QVRN2 YDRDK YDRDJ YDRDH YDRDG YDRDF YDRDY YDRDX YDRDC YDRDV YDRDB YDRDN YDRDM YDRD2 YDRD3 YDRD4 YDRD5 YDRD6 YDRD7 YDRD8 YDRD9 YDRYQ YDRYW Link to comment Share on other sites More sharing options...
Nine Posted October 4, 2019 Share Posted October 4, 2019 (edited) #include <File.au3> local $aFile, $aTxt _FileReadToArray("more.txt", $aFile) _ArrayDisplay ($aFile) For $i = 1 to $aFile[0] $aTxt = StringSplit ($aFile[$i], "", $STR_NOCOUNT) $aTxt = _ArrayUnique ($aTxt) If $aTxt[0] <= 3 Then ContinueLoop ConsoleWrite ($aFile[$i] & @CRLF) Next Try this Edited October 4, 2019 by Nine Alitai 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted October 4, 2019 Share Posted October 4, 2019 (edited) Also this: Local $aFile = FileReadToArray(@ScriptDir & "\more.txt") Local $hFilehandle = FileOpen(@ScriptDir & "\less.txt", $FO_OVERWRITE) For $s In $aFile If Not StringRegExp($s, "^(.)\g-1\g-1..|^(.)\g-1.\g-1.|^(.)\g-1..\g-1|^(.).\g-1\g-1.|^(.).\g-1.\g-1|^(.)..\g-1\g-1|^.(.)\g-1\g-1.|^.(.)\g-1.\g-1|^.(.).\g-1\g-1|^..(.)\g-1\g-1") Then FileWriteLine($hFilehandle, $s) Next FileClose($hFilehandle) Edited October 4, 2019 by jchd Fixed idiotic copy Alitai 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Alitai Posted October 4, 2019 Author Share Posted October 4, 2019 5 minutes ago, Nine said: #include <File.au3> local $aFile, $aTxt _FileReadToArray("more.txt", $aFile) _ArrayDisplay ($aFile) For $i = 1 to $aFile[0] $aTxt = StringSplit ($aFile[$i], "", $STR_NOCOUNT) $aTxt = _ArrayUnique ($aTxt) If $aTxt[0] <= 2 Then ContinueLoop ConsoleWrite ($aFile[$i] & @CRLF) Next Try this You missed a few. for example: QWQQN This must also be removed. There are 10 combinations to test. thanks for this short script this is crazy crazycrazy... i would never be able to made it so short.. Regards Alitai Link to comment Share on other sites More sharing options...
Nine Posted October 4, 2019 Share Posted October 4, 2019 replace 2 by 3, it is corrected in my script, typo.... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted October 4, 2019 Share Posted October 4, 2019 Did mine work for you? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Nine Posted October 4, 2019 Share Posted October 4, 2019 Since you like short : #include <File.au3> local $aFile _FileReadToArray("more.txt", $aFile) For $i = 1 to $aFile[0] If _ArrayUnique (StringSplit ($aFile[$i], "", $STR_NOCOUNT))[0] <= 3 Then ContinueLoop ConsoleWrite ($aFile[$i] & @CRLF) Next “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Alitai Posted October 4, 2019 Author Share Posted October 4, 2019 7 minutes ago, Nine said: replace 2 by 3, it is corrected in my script, typo.... Your script takes out 2 doubles also. Like: YDRDY But thats okay. Because that's what i doing in the 2nd run with a other script at the Moment. Can you confirm? @jchd: The other Script i will test in a sec... Thanks Regards Alitai Link to comment Share on other sites More sharing options...
jchd Posted October 4, 2019 Share Posted October 4, 2019 I fixed it right now This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Alitai Posted October 4, 2019 Author Share Posted October 4, 2019 12 minutes ago, jchd said: I fixed it right now Okay, no it does not work (as you already know). But i understand how you do it (more or less). Also a great way. Link to comment Share on other sites More sharing options...
jchd Posted October 4, 2019 Share Posted October 4, 2019 The fixed version should work. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Nine Posted October 4, 2019 Share Posted October 4, 2019 46 minutes ago, Alitai said: Can you confirm? Yes you are right. It is removing 2 doubles. Then try using this to solve the issue : #include <File.au3> local $aFile, $aTxt, $sSort _FileReadToArray("more.txt", $aFile) For $i = 1 to $aFile[0] $aTxt = StringSplit ($aFile[$i], "", $STR_NOCOUNT) _ArraySort ($aTxt) $sSort = _ArrayToString ($aTxt, "") If StringRegExp ($sSort, "(.)\g1\g1") Then ContinueLoop ConsoleWrite ($aFile[$i] & @CRLF) Next “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Alitai Posted October 4, 2019 Author Share Posted October 4, 2019 14 minutes ago, jchd said: The fixed version should work. Yes, now it works. Thanks so much. @Nine Ahh cool! Thank you too. I have now to Test everything with bigger lists. Thank you all so much for the help. Crazy Thanks Regards Alitai Link to comment Share on other sites More sharing options...
Nine Posted October 4, 2019 Share Posted October 4, 2019 I tested both solution, and jchd's one is about 20x faster than mine. But if I can agree that jchd's is 20x more abstruse, it is still the best solution. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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