Board logo

标题: [文件操作] 批处理怎样实现字符查找替换? [打印本页]

作者: wolai_1    时间: 2010-5-28 14:53     标题: 批处理怎样实现字符查找替换?

例:我在D:\test文件夹里有两个文件,WEB.XML,CONF.JS,想写个批处理文件MY.BAT放在D:\test下
功能:
      1.找到MY.BAT的路径,即(D:\test)
      2.然后根据此路径,得到WEB.XML,CONF.JS文件
      3.用命令查到自己的IP
      4.在这两个文件里找到:192.155.1.111这个串,用自己的IP代替
作者: wolai_1    时间: 2010-5-28 15:14

@echo off
ipconfig /all >ipconfig.txt
type ipconfig.txt
if exist IP.txt del IP.txt
find "IP Address" ipconfig.txt >IP.txt
for /f "delims= " %%I in (IP.txt)
echo %ip%
.......不知道怎么写了
  pause
作者: backup    时间: 2010-5-28 16:17

echo %ip%?前面没提到

del ipc.txt /q>nul
for /f "delims=" %%a in (web.xml) do (
set jj=%%a
set hh=!jj:192.155.1.111=yourip!
echo.!hh!>>ipc.txt
)
del web.xml
ren ipc.txt web.xml
作者: hanyeguxing    时间: 2010-5-28 17:06

  1. @echo off&setlocal enabledelayedexpansion&chcp 437 >nul&Graftabl 936 >nul
  2. for /F "tokens=1,2*" %%a in ('ipconfig') do if /i "%%a%%b"=="IPAddress." (
  3. set c=%%c
  4. set c=!c:*:=!
  5. set c=!c:~1,-1!
  6. )
  7. for %%a in (WEB.XML CONF.JS) do (
  8. (for /F "delims=" %%b in ('type "%%a"^|more') do (
  9. set b=%%b
  10. setlocal enabledelayedexpansion
  11. set "b=!b:192.155.1.111=%c%!"
  12. echo.!b!
  13. Endlocal))>$
  14. move $ "%%a")
复制代码





欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2