Subz Posted March 1, 2018 Posted March 1, 2018 Maybe use something like: nb: Untested. #include <Array.au3> #include <File.au3> Local $aFileRead _FileReadToArray("C:\AutomationDevelopers\temp.txt", $aFileRead, 0) _ArrayDisplay($aFileRead, ":: Before ::") For $i = UBound($aFileRead) - 1 To 0 Step - 1 If StringRegExp($aFileRead[$i], '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?') Then _ArrayDelete($aFileRead, $i) Next _ArrayDisplay($aFileRead, ":: After ::") Local $hFileOpen = FileOpen("C:\AutomationDevelopers\Updated.txt", 2) _FileWriteFromArray($hFileOpen, $aFileRead) FileClose($hFileOpen)
florian2 Posted March 1, 2018 Author Posted March 1, 2018 yes i get the "before", but no way to get the after with the gui
Subz Posted March 1, 2018 Posted March 1, 2018 Just move the _ArrayDisplay($aFileRead, ":: After ::") above Next
Earthshine Posted March 1, 2018 Posted March 1, 2018 28 minutes ago, florian2 said: so far : #include <file.au3> $file = FileOpen("C:\AutomationDevelopers\temp.txt", 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $line= StringRegExpReplace($line, '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?', "") MsgBox(0,'',$line) WEnd FileClose($file) at least it show correcly line by line the right word, that encouraging. but how to actually delete the line in the file ? How about you just create a new file with the proper output and then delete the old one and rename the new what the old one was named My resources are limited. You must ask the right questions
florian2 Posted March 1, 2018 Author Posted March 1, 2018 (edited) good, but i need to click many times on the "x" to have the after, like it rule every line each time Edited March 1, 2018 by florian2
Subz Posted March 1, 2018 Posted March 1, 2018 "but no way to get the after with the gui " Maybe I understood you incorrectly are you saying that the ":: After ::" didn't display after it finished? I thought you meant you wanted to display the ":: After ::" as it went through the list like your MsgBox in Post 20. Can you please confirm?
florian2 Posted March 1, 2018 Author Posted March 1, 2018 Actually it work, the only problem is i need to click on the "x" to advance the program manually line by line. Exemple if there is 10 lines, i need to click 10 times on the "x" of the gui to advance the program. Once i'v clicked 10 times, the result is good. I would like to just have the final result in the updated.txt
florian2 Posted March 1, 2018 Author Posted March 1, 2018 (edited) Oups yeah the first version actually worked much better, i made a mistake xD sorry i try with 1 million lines txt to see how it goes, i think it will be good Edited March 1, 2018 by florian2
mikell Posted March 1, 2018 Posted March 1, 2018 14 minutes ago, Subz said: Just move the _ArrayDisplay($aFileRead, ":: After ::") above Next Well, _ArrayDisplay can display 65525 elements only. So good luck to display millions of lines (as said the OP in post #16) - and BTW with _Array* funcs too Earthshine 1
Subz Posted March 1, 2018 Posted March 1, 2018 Whoops didn't see that that post, then I suppose @florian2 could try: #include <file.au3> Local $hFileRead = FileOpen("C:\AutomationDevelopers\temp.txt") Local $hFileOpen = FileOpen("C:\AutomationDevelopers\Updated.txt", 2) While 1 $sFileLine = FileReadLine($hFileRead) If @error = -1 Then ExitLoop If StringRegExp($sFileLine, '(?m)(?|^.*?a.*?e.*$|^.*?e.*?a.*$)\R?') Then ConsoleWrite("Remove: " & $sFileLine & @CRLF) ContinueLoop Else ConsoleWrite("Add: " & $sFileLine & @CRLF) FileWrite($hFileOpen, $sFileLine & @CRLF) EndIf WEnd FileClose($hFileRead) FileClose($hFileOpen) florian2 1
Malkey Posted March 2, 2018 Posted March 2, 2018 This example processes a million line file. Most of the run time is taken up displaying the results. Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Local $sFileName = "AAATestFile.txt" ; ========= Create & Display Example test file ========== If FileExists($sFileName) Then FileDelete($sFileName) Local $str For $i = 1 To 1000000 ; 1,000,000 line file $str &= $i & "/" & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & ChrW(Random(97, 102, 1)) & @CRLF Next FileWrite($sFileName, $str) Run("notepad.exe " & $sFileName) $hWin1 = WinWait($sFileName, "", 0) WinMove($hWin1, "", 0, 0, @DesktopWidth / 4, @DesktopHeight) WinSetTitle($sFileName, "", "Unaltered File") ; ====== End of Create & Display Example test file ======= Local $sFileContents = FileRead($sFileName) FileDelete($sFileName) FileWrite($sFileName, StringRegExpReplace($sFileContents, '.*(a.*e|e.*a).*\R*', "")) Run("notepad.exe " & $sFileName) $hWin2 = WinWait($sFileName, "", 0) WinMove($hWin2, "", @DesktopWidth / 4, 0, @DesktopWidth / 4, @DesktopHeight) florian2 1
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