标题: [文本处理] 批处理怎样实现字符的查找与替换? [打印本页]
作者: sbjatje 时间: 2010-9-8 17:37 标题: 批处理怎样实现字符的查找与替换?
我想为一个安装软件写一个批处理让其自动运行,,,现要遇到问题了,
在D:\crack下面有一个 03.txt文件 里面有这些内容:
###################################################################
#
# replace 00-1D-7D-74-B5-C7 in every-feature with your real ptc_hostid
# as shown in setup
#
###################################################################
INCREMENT PROE_DDiTy ptc_d 29.0 permanent uncounted \
VENDOR_STRING="VSVER=2.0 LO=(0,3,6,7,9,10,14,16,17,19,21,22, \
23,24,25,26,29,30,31,32,34,35,36,37,40,41,45,47,48,51,52,53, \
54,55,56,57,59,60,61,62,63,65,66,67,69,71,72,73,74,77,91,92, \
93,94,97,100,104,106,108,115,116,117,118,119,120,121,122,123, \
125,126,127,128, 131,133,134,135, 137,139,140,141,148,155,156, \
158,160,163,164,167,168,187,188,189,190,191,192,193,194,208,209,210, \
213,214,218,219,220,221,222,223,224,251,253,259,260,261,262,263,264,275)" SUPERSEDE \
HOSTID=PTC_HOSTID=00-1D-7D-74-B5-C7 vendor_info="VIVER=2.0 EXTERNAL_NAME=" ISSUER=ODT \
ISSUED=2-apr-2006 NOTICE=PTC SN=07071982 SIGN="092F DBD8 F7BA
我想把上面的txt文件中的 00-1D-7D-74-B5-C7 查找出来,并改为电脑的id号(电脑的id号是通过开始--运行--cmd--d:
cd \proeWildfire 4.0\bin
ptchostid.bat
会得到一组数据, 请问要把001-1D-7D-74-B5-C7 改成运行ptchostid.bat得到的数据,批处理文件应该如何写
请路过的高手们帮我看下,万分感谢,,,
[ 本帖最后由 sbjatje 于 2010-9-10 10:21 编辑 ]
作者: bugs 时间: 2010-9-9 10:32
搜索下再发问比较好
http://bathome.l3.wuyou.com/viewthread.php?tid=8304&highlight=%CC%E6%BB%BB
作者: sbjatje 时间: 2010-9-9 10:58 标题: 去看了一下
照着做是能做出来,但不明白下面这些是什么意思!
路过的大侠们,帮忙解释下,,,谢谢了- @echo off
- (for /f "delims=" %%a in (a.txt) do (
- set str=%%a
- setlocal enabledelayedexpansion
- echo;!str:aaaaa=bbbbb!
- endlocal
- ))>tem
- move tem a.txt
- start a.txt
复制代码
[ 本帖最后由 sbjatje 于 2010-9-9 13:40 编辑 ]
作者: Batcher 时间: 2010-9-9 12:53 标题: 回复 3楼 的帖子
把问题都更新到顶楼吧
作者: sbjatje 时间: 2010-9-9 13:10 标题: 更新好了,
请大家都帮我看下,,,,
作者: BAT1 时间: 2010-9-9 17:29 标题: 回复 1楼 的帖子
本批处理替换a.txt文本,另外希望楼主不要重复发贴。- @echo off
- echo 本批处理将替换a.txt中的00-1D-7D-74-B5-C7字符串为本机Physical Address字符串
- pause>nul
- for /f "delims=:, tokens=1,2,3" %%i in ('ipconfig/all') do (
- if "%%i"==" Physical Address. . . . . . . . . " set PA=%%j
- )
- echo %pa%
-
- (for /f "delims=:, tokens=1,2,3" %%i in (a.txt) do (
- setlocal enabledelayedexpansion
- set b=%%i
- set c=!b:00-1D-7D-74-B5-C7=%pa%!
- echo.!c!%%j%%k
- endlocal
- ))>b.txt
- start "" "a.txt"
- start "" "b.txt"
- exit
复制代码
作者: sbjatje 时间: 2010-9-9 18:54 标题: 先研究下,,,
这个批处理,会多产生一个b.txt的文件,能不能不产生b.txt 直接替换原来的txt文件里的Physical Address
还有就是,中途要回车一次,能不能不回车,自动完成
[ 本帖最后由 sbjatje 于 2010-9-9 20:00 编辑 ]
作者: sgaizxt001 时间: 2010-9-9 20:56
- @echo off
- setlocal enabledelayedexpansion
- for /f "tokens=2 delims=:" %%a in ('ipconfig /all ^|findstr /i /c:"physical address"') do set mac=%%a
- (for /f "delims=" %%i in (03.txt) do (
- set str=%%i
- set str=!str:00-1D-7D-74-B5-C7=%mac%!
- echo !str!
- ))>tmp_
- del 03.txt
- ren tmp_ 03.txt
复制代码
作者: sbjatje 时间: 2010-9-9 21:22 标题: 收下来,研究下,,,
谢谢sgaizxt001
作者: CUer 时间: 2010-9-9 21:33
- sed "/replace/!d; s/.*replace \([^ ]\+\) .*/\1/" "D:\crack\03.txt"
复制代码
作者: sbjatje 时间: 2010-9-10 10:06 标题: 楼上的,为什么只有一句呀,,,
能简单的简说下吗?
谢谢了
作者: sgaizxt001 时间: 2010-9-10 14:49
ptchostid.bat得到的数据是什么数据?
可否看看你的ptchostid.bat内容?如果可行的话,把两个批处理整合成一个会比较好
作者: zldfsz 时间: 2010-10-28 21:24 标题: ptchostid.bat内容
回复sgaizxt001 很满意你的代码,不过你的代码替换后在物理地址前有一个空格符,能不能改进下,把空格符去掉???
ptchostid.bat内容如下。
@echo off
set MC=unset
if "%PROCESSOR%" == "INTEL_64" set MC=ia64_nt
if "%PROCESSOR%" == "INTEL_486" set MC=i486_nt
if "%PROCESSOR_ARCHITECTURE%" == "IA64" set MC=ia64_nt
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" set MC=x86e_win64
if "%PROCESSOR_ARCHITECTURE%" == "x86" set MC=i486_nt
if not "%MC%" == "unset" goto mc_done
echo ERROR Cannot detect what machine type you have.
echo Please make one of the following settings:
echo.
echo set PROCESSOR=INTEL_486 - For Windows NT Intel based machines.
echo.
echo set PROCESSOR=INTEL_64 - For Windows Intel Itanium based machines.
echo.
echo set PROCESSOR_ARCHITECTURE=AMD64 - For Windows AMD 64 based machines.
echo.
exit
:mc_done
set PRO_MACHINE_TYPE=%MC%
if "%PROOBJ_START_DIRECTORY%" == "" set PRO_DIRECTORY=
if NOT "%PRO_DIRECTORY%" == "" "%PRO_DIRECTORY%\bin\%MC%_ptc_setvars" %0 "ptchostid" bat
if "%PRO_DIRECTORY%" == "" %MC%_ptc_setvars %0 "ptchostid" bat
call ptc_setvars.bat
del ptc_setvars.bat
set start_cmd=start ""
set PRO_DIRECTORY=%PRODIR%
if NOT "%PTCPATH%" == "" goto ptcpathset
set path=%PRO_DIRECTORY%\bin;%path%
set PTCPATH=true
:ptcpathset
if NOT "%mc%" == "x86e_win64" goto x86do
if EXIST "%prodir%\%mc%\obj\cpu_id.exe" goto x86do
set MC=i486_nt
:x86do
"%PRODIR%\%MC%\obj\cpu_id.exe" %1 %2 %3 %4 %5
:ptc_end
exit /B %ERRORLEVEL%
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |