bat file to replace string in text file

前端 未结 4 604
失恋的感觉
失恋的感觉 2021-01-22 04:23

This question has been asked a lot on stackoverflow, but I can\'t seem to be able to make it work. Any hints appreciated. Here is a text file (extension .mpl) containing offendi

4条回答
  •  故里飘歌
    2021-01-22 04:29

    You defined delims=, that's a bad idea if you want to preserve your lines, as it splits after the first space.
    You should change this to FOR /F "tokens=* delims=" ....

    Your echo !str! >> testCleaned.mpl will always append one extra space to each line, better use echo(!str!>>testCleaned.mpl.

    You will also lose all empty lines, and all exclamation marks in all lines.

    You could also try the code of Improved BatchSubstitute.bat

提交回复
热议问题