Jump to content
Sign in to follow this  
Lesler

I'm trying to find and replace some text.

Recommended Posts

Lesler

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

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Lesler

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"

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Lesler

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.txt

liste_til_pro.txt

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Lesler

Hi Water

Many thanks for your help.

It works perfectly.

You have saved me many hours of work

Martin

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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
Sign in to follow this  

×