Roth Posted April 13, 2018 Share Posted April 13, 2018 Hello, I am trying to make a script that edits log file to something more easy to read - in the log file there are informations with money inserted etc. etc. in format like 20000 and i want to change it to 200Kč and more things like changing text etc. etc. The problem is that the StringReplace stops at circa half the file... the log file has 3000 - 10 000 lines (it depends how much the till is used and what time it is....). So i want to ask, is the stringreplace somehow limited ? It looks like that it always stop at half file and no matter if its 3000 lines or 8000 lines (it starts from bottom and goes up) or is this code wrong ? $szText2 = FileRead($file2) $szText2 = StringReplace($szText2, "20000", "200Kč") FileWrite($file2,$szText2) Thank you Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 (edited) Roth, Could you please post an example file - it is always easier to deal with a real-world case. M23 P.S. Welcome to the AutoIt forums. Edited April 13, 2018 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 (edited) Hello Melba23, Script attached - i know it will be confusing to read but i just started with autoit, btw there is a StringRegExpReplace to remove blank lines because i though that is the problem but it also stops at half the page P.S. If you know how to add another 100 stores with 5 SCO tills that have their own IPs with some easier way than i have in the script (3 so far and 2 not completed ) i would be really grateful Edited April 16, 2018 by Roth Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 Roth, I actually wanted an example of the file you are trying to manipulate! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 Ops Sorry, script copies the log file from page then creates txt file and copies the text inside and saves and close it. Example text: 2018/04/13,08:05:54.735,[INF],3599454578,,Change Given,0,CZK:50000:0:1/CZK:20000:0:1/CZK:5000:0:1/CZK:2000:0:1/CZK:500:0:1/CZK:200:0:2 2018/04/13,08:08:28.538,[INF],3599618563,,Deposit,0,CZK:10000:0:1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 Roth, So that is an example of a single line and you say there are some 3-10000 of them in the file. What is the EOL delimiter? To explain: I am trying to see if I can reproduce your problem on a representative file - can you not post an example of a whole file? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 Log ends with two blank lines if that is what you ask... Throughout the file there are circa three more blank lines The two lines i sent you are throughout the whole log file but ofc with different time, amount etc. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 Roth, And what is the EOL delimiter? How does the file signify a new line? @CRLF? @CR? @LF? Could there possibly be some non-printing characters within it (which is what I suspect might be the problem)? In your script you are saving the files to manipulate them later - why not just post one of them! Help us to help you! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 I tried to remove @CRLF @CR and @LF but its still the same OK, here is the example log file - it was already edited so you can see that it has only done circa half the file log.txt Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 Roth, Using the half-modified file you posted, I recreated a larger file of over 10,000 lines and all instances of "20000" were successfully changed: ; Read in file snippet $sSnipText = FileRead("Snip_Log.txt") ; Check how many "20000" we can find WITHOUT changing any of then StringReplace($sSnipText, "20000", "") ; The answer was 5 ConsoleWrite(@extended & @CRLF) ; The answer was 5 ; Create a new file of suffcient size $sNew_Log = "" For $i = 1 To 300 $sNew_Log &= $sSnipText Next FileWrite("New_Log.txt", $sNew_Log) Sleep(1000) ; Allow thew system to settle ; Read large file $sLogText = FileRead("New_Log.txt") ; Replace the "20000" instances $sChgText = StringReplace($sLogText, "20000", "200Kè") ; How many? ConsoleWrite(@extended & @CRLF) ; The answer was 1500 which is what is expected ; Save the file FileWrite("Chg_log.txt", $sChgText) ; Visual inspection confirms the change Can you please let me have an ORIGINAL file - just as you get it from the web - as there must be something within that file which is causing the problem. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 OK i just downloaded this one but it has only 333 lines and its the same problem... log2.txt Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 Well, i think i know where might be the problem... for some reason it copies the text two times and then the script edits only the last copy. But i can not figure out why the script copies the text two times ? Because if i look at the log2.txt i can see there are only 333 lines but if run the script and download the same log file its saved two times in the txt... Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 Roth, That is obvious now I look at the script: $sText = FileRead($FILE2) $sText = StringRegExpReplace(StringRegExpReplace($sText, "(\v)+", @LF), "(^\v*)|(\v*\Z)", "") FileWrite($FILE2, $sText) ; Write the modified text <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Sleep(150) $szText2 = FileRead($FILE2) ;FileGetSize($File2)) $szText2 = StringReplace($szText2, "20000", "200Kè") FileWrite($FILE2, $szText2) ; Append the changed text <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Remember that FileWrite appends text to a file. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 Well, Can I somehow change the text without the filewrite copying it ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 Roth, Why write it at all the first time? Just keep the text as a variable until you have completed all the required steps and then write it just the once. Better still, use FileOpen in "overwrite" mode and then you will be sure to have just the final text. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 I got it to work - after ^C i used $varclip = clipget() and it works Thank you very much !! Link to comment Share on other sites More sharing options...
Developers Jos Posted April 13, 2018 Developers Share Posted April 13, 2018 Why using the clipboard at all since this is asking for trouble? What is wrong simply using fileread/write statements and ensuring you overwrite the original file? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2018 Moderators Share Posted April 13, 2018 Roth, What he said! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Roth Posted April 13, 2018 Author Share Posted April 13, 2018 OK, got that working too Thank you 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