run a script to rename several words in a txt file

人走茶凉 提交于 2019-12-02 04:24:13

Here you go:

@echo off
setlocal enabledelayedexpansion
(for /f "tokens=*" %%f in (input1.txt) do (
        set "line=%%f"
        set "line=!line:LX4XAB=LX4xab!"
        set "line=!line:XS3X44=Xs3x44!"
        echo(!line!
)) > newfile.txt

Revision 1

Here is how you can do it with multiple files and doing the naming the way you asked for.

@echo off
setlocal enabledelayedexpansion
cd /d C:\Temp
for %%a in (*.txt) do (
  echo %%~nxa|Find /i "_new">nul
  if errorlevel 1 (
    (for /f "tokens=*" %%f in (%%a) do (
        set "line=%%f"
        set "line=!line:LX4XAB=LX4xab!"
        set "line=!line:XS3X44=Xs3x44!"
        echo(!line!
    )) > %%~na_new.txt
  ) 
  echo %%~nxa|Find /i "_new">nul
  if errorlevel 1 ren %%~nxa %%~na.old
)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!