Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: BinaryPeekStr
I know BinaryPokeStr can add a new line to a file, though I can't figure how replace a text string with a new string. ie., testfile.txt contains:
the dog is green the dog is blue the dog is blue the dog is red the dog is redHow would I replace all "the dog is red" lines with the "dog is red"? (exclude the "the" in the sentence?)
;=========Modify these variables as needed============== infind="the dog is red" outReplace="dog is red" infilename="C:\Temp\testfile.txt" outfilename="C:\Temp\testfileout.txt" ;================================================================== if fileexist(infilename)==0 message("Oh No!","File %infilename% doesn't exist") exit endif insize=FileSize(infilename) inbuffer= BinaryAlloc(insize) BinaryRead(inbuffer, infilename) BinaryReplace(inbuffer, infind, outReplace, @FALSE) BinaryWrite(inbuffer,outfilename) BinaryFree(inbuffer) ;==================================================================
;=========Modify these variables as needed============== infind=@crlf outReplace=@lf infilename="C:\Temp\testfile.txt" outfilename="C:\Temp\testfileout.txt" ;================================================================== if fileexist(infilename)==0 message("Opps","File %infind% doesn't exist") exit endif insize=FileSize(infilename) inbuffer= BinaryAlloc(insize) BinaryRead(inbuffer, infilename) BinaryReplace(inbuffer, infind, outReplace, @FALSE) BinaryWrite(inbuffer,outfilename) BinaryFree(inbuffer)
Article ID: W12734
Filename: Search and Replace Another Example.txt
File Created: 2018:09:09:09:28:12
Last Updated: 2018:09:09:09:28:12