pdavit Posted June 15, 2005 Share Posted June 15, 2005 Dear friends, First post here. I was wondering if it is possible to use AutoIt to have a script that will read some values of an ASCII file in the form of e.g. 999.501 and replace those values with some others. Example: Input text file contains the following: 999.501 999.502 999.503 999.505 999.500 999.504 999.508 999.518 I use some search and replace conditions like where 999.501 replace with 999.273, 999.502 replace with 999.274 and so on. I don't know if it is possible to have the replaced results saved on the same initial text file or if it is possible the result to be "exported" to another file name. I could do the above with a text editor supporting macros (eg PSPad) but the thing is that this procedure needs to be completely automated for use by totally inexperienced end users. Any ideas if this is feasible with AutoIt? Thank you very much in advance! Kind regards, Panos AutoIt Rules!!!... Link to comment Share on other sites More sharing options...
Flashz Posted June 15, 2005 Share Posted June 15, 2005 Dear friends,First post here. I was wondering if it is possible to use AutoIt to have ascript that will read some values of an ASCII file in the form of e.g. 999.501and replace those values with some others. Example:Input text file contains the following: 999.501999.502999.503999.505999.500999.504999.508999.518I use some search and replace conditions like where 999.501 replace with 999.273,999.502 replace with 999.274 and so on.I don't know if it is possible to have the replaced results saved on the sameinitial text file or if it is possible the result to be "exported" to anotherfile name.I could do the above with a text editor supporting macros (eg PSPad) but the thing is that this procedure needs to be completely automated for use by totally inexperienced end users. Any ideas if this is feasible with AutoIt? Thank you very much in advance!Kind regards,Panos<{POST_SNAPBACK}>Try the link below, I think it should be what your looking for:http://www.autoitscript.com/forum/index.ph...839entry68839 Link to comment Share on other sites More sharing options...
pdavit Posted June 15, 2005 Author Share Posted June 15, 2005 (edited) Try the link below, I think it should be what your looking for:http://www.autoitscript.com/forum/index.ph...5533;entry68839<{POST_SNAPBACK}>Thanks this seems to be working although the resulted conversion is saved over the initial file and not on a new one as shown in the script! Since I'm new to AutoIt can you please show me the code for more than a single convertion? Let's say three?Thank you!Edited: Plus why the new file is not created but the old one is overwritten? Edited June 15, 2005 by pdavit AutoIt Rules!!!... Link to comment Share on other sites More sharing options...
pdavit Posted June 15, 2005 Author Share Posted June 15, 2005 That's my final solution so far! Works great! expandcollapse popup; What it does: ; This AutoIt script searches a text file for specific strings and replaces ; them with pre-defined values. A new file is created with output results. ; Upon request, you can overwrite the initial file by uncommenting the ; related commands. ; Define your input file here: $filein = FileOpen("existing.txt",0) ; Define your output file here: $fileout = FileOpen("newfile.txt",2) While 1 $line = FileReadLine($filein) ; All string conversions are listed here: If @error = -1 Then ExitLoop If StringInStr($line,"999.501") Then $line1 = StringReplace($line,"999.501","999.273") FileWriteLine($fileout,$line1) ElseIf StringInStr($line,"999.502") Then $line1 = StringReplace($line,"999.502","999.274") FileWriteLine($fileout,$line1) ElseIf StringInStr($line,"999.503") Then $line1 = StringReplace($line,"999.503","999.275") FileWriteLine($fileout,$line1) ElseIf StringInStr($line,"999.505") Then $line1 = StringReplace($line,"999.505","999.276") FileWriteLine($fileout,$line1) ElseIf StringInStr($line,"999.500") Then $line1 = StringReplace($line,"999.500","999.270") FileWriteLine($fileout,$line1) ElseIf StringInStr($line,"999.508") Then $line1 = StringReplace($line,"999.508","999.271") FileWriteLine($fileout,$line1) ElseIf StringInStr($line,"999.518") Then $line1 = StringReplace($line,"999.518","999.272") FileWriteLine($fileout,$line1) Else FileWriteLine($fileout,$line) Endif Wend FileClose($filein) FileClose($fileout) ; If needed to overwrite existing file, uncomment the following two lines: ; FileDelete("existing.txt") ; FileMove("newfile.txt", "existing.txt") Exit AutoIt Rules!!!... 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