文件2.txt内容如下复制代码
- <?xml version="1.0" encoding="gb2312"?>
- <root>
- <PackTypeInfo PackType="188字节"/>
- <IPInfo IP="192.168.0.1" IPMask="255.255.255.0" GateWay="192.168.0.1" MAC="00-00-01-01-00-04"/>
- <DeModule Freq="714000000" SymbolRate="6875000"/>
- <CodeInfo CodeAddress="224.1.0.1" CodePort="5001" AnalysisAddress="224.2.0.1" AnalysisPort="5000"/>
- <CheckReset Reset="1"/>
- </root>
以此类推复制代码
- <?xml version="1.0" encoding="gb2312"?>
- <root>
- <PackTypeInfo PackType="188字节"/>
- <IPInfo IP="192.168.0.2" IPMask="255.255.255.0" GateWay="192.168.0.1" MAC="00-00-01-01-00-05"/>
- <DeModule Freq="714000000" SymbolRate="6875000"/>
- <CodeInfo CodeAddress="224.1.0.2" CodePort="5001" AnalysisAddress="224.2.0.2" AnalysisPort="5000"/>
- <CheckReset Reset="1"/>
- </root>
最终目的:复制代码
- 00-01-00-00-00-01
- 00-01-00-00-00-02
- 00-01-00-00-00-03
- 00-01-00-00-00-04
- 00-01-00-00-00-05
- 00-01-00-00-00-06
- 00-01-00-00-00-07
- 00-01-00-00-00-08
- 00-01-00-00-00-09
- 00-01-00-00-00-0a
- 00-01-00-00-00-0b
- 00-01-00-00-00-0c
- 00-01-00-00-00-0d
- 00-01-00-00-00-0e
- 00-01-00-00-00-0f
- 00-01-00-00-00-10
- 00-01-00-00-00-11
- 00-01-00-00-00-12
- 00-01-00-00-00-13
- 00-01-00-00-00-14
- 00-01-00-00-00-15
- 00-01-00-00-00-16
- 00-01-00-00-00-17
- 00-01-00-00-00-18
- 00-01-00-00-00-19
- 00-01-00-00-00-1a
- 00-01-00-00-00-1b
- 00-01-00-00-00-1c
- 00-01-00-00-00-1d
- 00-01-00-00-00-1e
- 00-01-00-00-00-1f
- 00-01-00-00-00-20
- 00-01-00-00-00-21
- 00-01-00-00-00-22
- 00-01-00-00-00-23
- 00-01-00-00-00-24
- 00-01-00-00-00-25
- 00-01-00-00-00-26
- 00-01-00-00-00-27
- 00-01-00-00-00-28
复制代码
- @echo off&setlocal enabledelayedexpansion
- for /f "delims=" %%i in (mac.txt) do set /a n+=1&set _!n!=%%i
- set "v=00-00-01-01-00-04"
- for /f "delims=" %%a in ('dir /b /a-d *.txt^|find /v "mac.txt"') do (
- set/a m+=1
- for %%b in (!m!) do set t=!_%%b!
- (for /f "usebackq delims=" %%i in ("%%a") do (
- set "str=%%i"
- for %%b in (!t!) do set str=!str:%v%=_%%b!
- echo !str!
- ))>~tem
- move /y ~tem "%%a"
- )
- pause
原帖由 terse 于 2009-8-4 16:02 发表
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (mac.txt) do set /a n+=1&set _!n!=%%i
set "v=00-00-01-01-00-04"
for /f "delims=" %%a in ('dir /b /a-d *.txt^|find /v "mac.txt"' ...
原帖由 wwenyunkui 于 2009-8-4 16:51 发表
非常感谢您的解答,目标是达到了,不过有一点遗憾:
1、在'dir /b /a-d *.txt时并不是按照数字1~40的顺序进行遍历所有txt文件的,最终结果导致1.txt文件中的“00-00-01-01-00-04”被替换为“_00-01-00-00-00-01” ...
复制代码
- @echo off&setlocal enabledelayedexpansion
- for /f "delims=" %%i in (mac.txt) do set /a n+=1&set _!n!=%%i
- set "v=00-00-01-01-00-04"
- for /l %%a in (1 1 40) do (
- (for /f "usebackq delims=" %%i in ("%%a.txt") do (
- set "str=%%i"
- for %%b in (!_%%a!) do set str=!str:%v%=%%b!
- echo !str!
- ))>~tem
- move /y ~tem "%%a.txt"
- )
- pause
原帖由 terse 于 2009-8-4 17:15 发表
确定文件名的话 是否可以这样
_00 这里多余了_ 改str=!str:%v%=_%%b! 为 str=!str:%v%=%%b!@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (mac.txt) do set /a n+=1&set _!n!=%%i
set ...
复制代码
- @echo off&setlocal enabledelayedexpansion
- set asc=0123456789abcdef
- set /a n=1,m=4
- md temp
- for /f "delims=" %%a in (mac.txt) do (
- set/p h2=m%%16,h1=m/16
- for /f "tokens=1,2" %%1 in ("!h1! !h2!") do (set h1=!asc:~%%1,1!&set h2=!asc:~%%2,1!)
- echo 处理文件!n!.txt
- (for /f "delims=" %%b in (!n!.txt) do (set str=%%b
- for %%k in (00-00-01-01-00-!h1!!h2!) do echo;!str:%%k=%%a!
- ))>>temp\!n!.txt
- set /a n+=1,m+=1
- )
- echo 更新文件存入temp目录
- pause
复制代码
- //&@cls&start wscript.exe -e:jscript "%~f0"&exit/b
- fso = new ActiveXObject('Scripting.FileSystemObject');
- omac = fso.OpenTextfile('mac.txt');
- for (i=1;i<=40;i++) {
- s = fso.OpenTextfile(i+'.txt').ReadAll();
- fso.OpenTextfile(i+'.txt',2).Write (
- s.replace(/(MAC=")[\da-f-]{17}/gi, '$1'+omac.ReadLine()) );
- }
原帖由 zqz0012005 于 2009-8-4 21:01 发表
注意是不可逆操作,使用前请自行备份。//&@cls&start wscript.exe -e:jscript "%~f0"&exit/b
fso = new ActiveXObject('Scripting.FileSystemObject');
omac = fso.OpenTextfile('mac.txt');
for (i=1;i
复制代码
- @echo off&setlocal enabledelayedexpansion
- for /f "delims=" %%i in (mac.txt) do set /a n+=1&set _!n!=%%i
- for /l %%a in (1 1 40) do (
- (for /f "usebackq tokens=*" %%i in ("%%a.txt") do (
- set "str=%%i"
- if "!str:~,11!"=="<IPInfo IP=" (
- for /f "tokens=5,7 delims==/" %%b in ("%%i/!_%%a!") do set str=!str:%%b=%%c!
- )
- echo !str!
- ))>~tem
- move /y ~tem "%%a.txt"
- )
- pause
原帖由 terse 于 2009-8-5 09:42 发表
原来的变量是固定的 修改下
发现这里一个FOR可省
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%i in (mac.txt) do set /a n+=1&set _!n!=%%i
for /l %%a in (1 1 40) do (
(for /f ...
Environment variable substitution has been enhanced as follows: %PATH:str1=str2% would expand the PATH environment variable, substituting each occurrence of "str1" in the expanded result with "str2". "str2" can be the empty string to effectively delete all occurrences of "str1" from the expanded output. "str1" can begin with an asterisk, in which case it will match everything from the beginning of the expanded output to the first |
欢迎光临 批处理之家 (http://bathome.net./) | Powered by Discuz! 7.2 |