需求是修改多个路径下的同一文件名的配置文件global.properties 将里面的192.168.8.103换成用户手动输入的IP
学着写了一点如下:- @echo off
- setlocal enabledelayedexpansion
- set a_dir=%~dp0\1
- set b_dir=%~dp0\2
- set c_dir=%~dp0\3
- set d_dir=%~dp0\4
- set replaced=192.168.8.103
- set all=
- set /p all=请输入替换的IP地址:
- for %%a in (%a_dir% %b_dir% %c_dir% %d_dir%) do (
- sed -i "s/%replaced%/%all%/g" "%%a\global.properties"
- )
- pause
复制代码 运行结果如下:- C:\DOCUME~1\ADMINI~1\??\???~1>(sed -i "s/192.168.8.103/192.168.8.210/g" "and\glo
- C:\DOCUME~1\ADMINI~1\??\???~1>(sed -i "s/192.168.8.103/192.168.8.210/g" "Setting
- s\Administrator\??\?????\\1\global.properties" )
- C:\DOCUME~1\ADMINI~1\??\???~1>(sed -i "s/192.168.8.103/192.168.8.210/g" "C:\Docu
- ments\global.properties" )
- C:\DOCUME~1\ADMINI~1\??\???~1>(sed -i "s/192.168.8.103/192.168.8.210/g" "and\glo
- bal.properties" )
- C:\DOCUME~1\ADMINI~1\??\???~1>(sed -i "s/192.168.8.103/192.168.8.210/g" "Setting
- s\Administrator\??\?????\\2\global.properties" )
- C:\DOCUME~1\ADMINI~1\??\???~1>pause-i "s/192.168.8.103/192.168.8.210/g" "Setting
- Press any key to continue . . . al.properties" )
复制代码 功能没有实现,请指正哪些地方写错了 |