dos全文本替换

来源:百度知道 编辑:UC知道 时间:2024/05/22 12:15:48
有一个txt文件,想把里面的1.1.1.1 全部替换成 2.2.2.2 ,大概有几千行吧。
我要的是批处理方法,想说“编辑--替换--。。。”的别说了。

@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%"

是必须在dos下替换吗?如果不是
1、最简单办法,在Win下打开txt文档用 编辑-替换-全部替换;缺点特慢
2、用 程序-附件-写字板 打开 编辑-替换-全部替换 (最好用Word);速度快,但保存时注意格式
3、下载UltraEdit 用其编辑替换,速度快,不存在格式的问题