Jump to content

I'm trying to find and replace some text.


Lesler
 Share

Recommended Posts

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

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 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 - 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 (NEW 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

 

Link to comment
Share on other sites

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 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 - 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 (NEW 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

 

Link to comment
Share on other sites

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 - 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 (NEW 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

 

Link to comment
Share on other sites

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) :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...