Lesler Posted January 25, 2010 Share Posted January 25, 2010 Hello I'm trying to find and replace some text. I have a large file with many lines in (approximately 100,000 lines) The file consists the contents of a directory Here is a selection with only 3 lines which I have made to test the X:\TSA\Special\10000-10500\10013\s699-10013-01.asm.9 X:\TSA\Special\10000-10500\10013\s699-10013-03.asm.8 X:\TSA\Special\10000-10500\10013\s699-10013-02.asm.6 I have replaced everything from the first "." asm.9 - asm.8 - asm.6 to "drw". so that I would like to have a line of text that looks like this X:\TSA\Special\10000-10500\10013\s699-10013-01.drw X:\TSA\Special\10000-10500\10013\s699-10013-03.drw X:\TSA\Special\10000-10500\10013\s699-10013-02.drw I have tried with the following code. But I have enough to admit that it does not work. FileOpen("X:\TSA\Special\programmer\status_80\liste_til_tegning\liste_til_pro.txt", 1) $File=FileRead("X:\TSA\Special\programmer\status_80\liste_til_tegning\liste_til_pro.txt") StringReplace($File,".*", "drw") FileClose("X:\TSA\Special\programmer\status_80\liste_til_tegning\liste_til_pro.txt") Are there any of you have good advice. Thanks in advance Martin Link to comment Share on other sites More sharing options...
water Posted January 25, 2010 Share Posted January 25, 2010 (edited) Stringreplace doesn't offer wildcards. You either have to use StringRegExpReplace (Regular Expressions) or use StringReplace($File,".asm.9", ".drw") StringReplace($File,".asm.8", ".drw") ... StringReplace($File,".asm.0", ".drw") Edited January 25, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Lesler Posted January 25, 2010 Author Share Posted January 25, 2010 Hello Thank you for your prompt response. But it is not only asm.9 - asm.8 - asm.6 Figures can be from 1 to xxx The only thing that is always the same. "Asm" But asm.xxx be replaced with ". Drw" Link to comment Share on other sites More sharing options...
water Posted January 25, 2010 Share Posted January 25, 2010 (edited) I played a bit with regular expressions. This should do what you need. It replaces ".asm.x" (where x can be 1 to 3 numbers) to .drw$File=FileRead("X:\TSA\Special\programmer\status_80\liste_til_tegning\liste_til_pro.txt") StringRegExpReplace($File,'.asm.\d{1,3}','.drw') FileWrite("X:\TSA\Special\programmer\status_80\liste_til_tegning\liste_til_pro_NEW.txt",$File)This script creates a new file so you can rerun the script as often as you like. Edited January 25, 2010 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Lesler Posted January 25, 2010 Author Share Posted January 25, 2010 Hello again Many thanks for your help. The program looks really exciting. But I do not know what is going wrong. The new file has the same content as the old. I just try to attach them. Will you look at them and see if you can see what goes wrong.liste_til_pro_NEW.txtliste_til_pro.txt Link to comment Share on other sites More sharing options...
water Posted January 25, 2010 Share Posted January 25, 2010 My bad. The script should look like:$File=FileRead("X:\TSA\Special\programmer\status_80\liste_til_tegning\liste_til_pro.txt") $NewString = StringRegExpReplace($File,'.asm.\d{1,3}','.drw') FileWrite("X:\TSA\Special\programmer\status_80\liste_til_tegning\liste_til_pro_NEW.txt",$NewString) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Lesler Posted January 25, 2010 Author Share Posted January 25, 2010 Hi Water Many thanks for your help. It works perfectly. You have saved me many hours of work Martin Link to comment Share on other sites More sharing options...
water Posted January 25, 2010 Share Posted January 25, 2010 Glad to be of service.And I've learned something new too. Because I always thought that regular expressions are quite difficult to learn. But the first step was easy (with a little help from the very good AutoIt docu) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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