0

I am trying to replace a certain character found in convert.txt. Now, every characters found in convert.txt will replace into a linefeed in a file.

I have this code:

for /f "delims=" %%s in (convert.txt) do (
    Type c:\PETER\%%a  | repl.bat "\%%s" "%%s\n" X > c:\PETER\%%a
  )

I tried to use the replace.bat suggestion on this page see here. Now, when I am trying to replace a large file's character into a line feed, the output is not complete. Do we have a limit on this case?

Community
  • 1
  • 1
PeterS
  • 724
  • 2
  • 15
  • 31

1 Answers1

1

As MC ND said in his comment, you cannot simultaneously read and write to the same file. You must write to a new file, and then replace the original with the new using MOVE.

for /f "delims=" %%s in (convert.txt) do (
  type "c:\PETER\%%a"  | repl.bat "\%%s" "%%s\n" X > "c:\PETER\%%a.new"
  move /y "c:\PETER\%%a.new" "c:\PETER\%%a" >nul
)

The MOVE operation is nearly instantaneous, no matter what the file size.

dbenham
  • 127,446
  • 28
  • 251
  • 390