herewasplato Posted January 18, 2006 Posted January 18, 2006 (edited) If 'C:\Temp\temp1.txt' contains about 10000 lines like this: This is line number 1 This is line number 2 This is line number 3 This is line number 1 This is line number 2 This is line number 3 .... ...and the string to replace is this: This is line number 2 ...and the desired output is to look like this: This is line number 1 This is line number 3 This is line number 1 This is line number 3 ...then might I suggest code like this:$ReplaceIt = "This is line number 2" & @CRLF $info = FileRead('C:\Temp\temp1.txt', FileGetSize('C:\Temp\temp1.txt')) $info = StringReplace($info,$ReplaceIt,"") FileOpen('C:\Temp\temp1.txt',2) FileWrite('C:\Temp\temp1.txt',$info)This processed about 10000 lines in less than 2 seconds ...but I would be willing to bet that randallc's method is faster. You might have to play with @CRLF depending on what your files uses - might just be @CR or @LF. You can add in the file error checking and you can write to a different file if you wish, I was just posting the concept. Edit1: changed the lines to about 10000 and timed the script Edit2: apparently I payed too much attention to the input/output in the first post without noticing that string being searched for could be (and probably is) a subset of one line in the input file and not the entire line itself... chased the wrong rabbit again! Edited February 1, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size]
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