TheDcoder Posted March 15, 2015 Posted March 15, 2015 Hello, I found that its quite challenging to do this: text.txt: Hello, I am a text file :). I love line No. 1 I want to change it like this: I am line No. 1 now :P Hello, I am a text file :). I love line No. 1 How can I do this in AutoIt without storing it? Here is a straight-forward version of my question: How to insert text at the starting point of the document without storing it in a variable b/c my program processes very large text files? (minimum 1 GB) Thanks in advance! TD EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
TheDcoder Posted March 15, 2015 Author Posted March 15, 2015 (edited) >_FileWriteToLine Stores the contents of the file in the memory..... TD Edited March 15, 2015 by TheDcoder EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
water Posted March 15, 2015 Posted March 15, 2015 But this function does what you wanted to avoid. It reads the whole file into a single variable and then uses stringsplit to create an array with the same name. Means: It will use a lot of membory. I suggest to read the file line by line, insert a new line where needed and then delete the original file. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
TheDcoder Posted March 15, 2015 Author Posted March 15, 2015 @water Thanks you saved me EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
water Posted March 15, 2015 Posted March 15, 2015 Use FileOpen, FileRead, FileWrite and FileClose for best performance. Reading the file line by line (using FileReadLine) might be too slow. Use FileRead to read the file in chunks of e.g. 1MB. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
JohnOne Posted March 15, 2015 Posted March 15, 2015 (edited) $hFile = FileOpen("Product.txt", 1) ; Open file For write append FileSetPos($hFile, 0, 0) ; Set pos to beginning FileWriteLine($hFile, "New Line 1") ; Write line FileClose($hFile) ; Close file EDIT: Does not work, sorry. Edited March 15, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
water Posted March 15, 2015 Posted March 15, 2015 Doesn't work here - it simply overwrites the file. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
TheDcoder Posted March 15, 2015 Author Posted March 15, 2015 Doesn't work here - it simply overwrites the file. Me too EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
water Posted March 15, 2015 Posted March 15, 2015 Seems the only possible way to insert lines is to rewrite the file as I have described above. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
TheDcoder Posted March 15, 2015 Author Posted March 15, 2015 @water I would be sad if its true EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
mpower Posted March 15, 2015 Posted March 15, 2015 Could also look at using sed (e.g. https://unix.stackexchange.com/questions/87772/add-lines-to-the-beginning-and-end-of-the-huge-file) Might need to look into using Cygwin to achieve the effect under Windows: https://stackoverflow.com/questions/127318/is-there-any-sed-like-utility-for-cmd-exe
JohnOne Posted March 15, 2015 Posted March 15, 2015 Oops. Apologies. It worked in my head, and the test file I used, could not tell what had happened. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
water Posted March 15, 2015 Posted March 15, 2015 First thing I usually ask: Why do you need to insert lines in such a large file? What kind of file do you process (log files etc.)? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
TheDcoder Posted March 15, 2015 Author Posted March 15, 2015 First thing I usually ask: Why do you need to insert lines in such a large file? What kind of file do you process (log files etc.)? Log files with 5 years of age EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
JohnOne Posted March 15, 2015 Posted March 15, 2015 Crikey! I think the script you should be writing is one to get that data into some sort of database, and use that. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
water Posted March 15, 2015 Posted March 15, 2015 A log file stores events and describes what has happend. By definition a log file shouldn't be changed. If you need to insert records for reporting purposes then I suggest to use a report generator (e.g. Crystal Reports). My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
TheDcoder Posted March 15, 2015 Author Posted March 15, 2015 @water I prefer to keep my purpose for editing log with autoit confidential, please understand EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
JohnOne Posted March 15, 2015 Posted March 15, 2015 Your purpose is irrelevant, your method is what's in question. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
TheDcoder Posted March 15, 2015 Author Posted March 15, 2015 (edited) I am simply adding some extra details to the log files like username, check-sum and then encrypting it Edited March 15, 2015 by TheDcoder EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
JohnOne Posted March 15, 2015 Posted March 15, 2015 Simply eh! A 1 GB text file is not big and not clever, you are finding out why. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
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