标题: 批处理如何查找并替换指定字符串
[打印本页]
作者: zcydez
时间: 2010-6-22 14:37
标题: 批处理如何查找并替换指定字符串
当前目录下有个a.txt,里面有好多字符,请问如何用批处理吧里面所有的“aaaaa”字符串替换成“bbbbb”字符串?(不带引号)
作者: rockyuan
时间: 2010-6-22 14:42
sed '/aaaaa/' c\ "bbbbb" a.txt
作者: zcydez
时间: 2010-6-22 14:44
标题: 回复2楼
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>sed /?
'sed' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
C:\Documents and Settings\Administrator>
作者: rockyuan
时间: 2010-6-22 14:52
下载一个sed.exe 4个文件拷贝到windows/system32 <-系统默认位置
作者: zcydez
时间: 2010-8-12 13:32
不用了
我已经有纯批处理的方法了。
谢谢2楼
作者: zxgzhj
时间: 2010-8-13 21:05
@echo off
setlocal enabledelayedexpansion
set file=
set /p file= 请输入要操作的文件名称(包括扩展名):
set "file=%file:"=%"
for %%i in ("%file%") do set file=%%~fi
echo.
set replaced=
set /p replaced= 请输入即将被替换的内容:
echo.
set all=
set /p all= 请输入替换字符串:
for /f "delims=" %%i in ('type "%file%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
echo !str!>>"%file%"_tmp.txt
)
copy "%file%" "%file%"_bak.txt >nul 2>nul
move "%file%"_tmp.txt "%file%"
start "" "%file%"
作者: 88235268
时间: 2010-8-20 15:41
收藏。。。mark...