- @echo off
- cd %~dp0
-
- set file="%cd%\Ss.txt"
-
- set "file=%file:"=%"
- for %%i in ("%file%") do set "file=%%~fi"
- echo.
- set replaced=bbb-T2 ̨
- echo.
- set all=mmm
-
- cd.>"%file%_tmp.txt"
- setlocal enabledelayedexpansion
- for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%file%"') do (
- set str=%%j
- if not "!str!"=="" set "str=!str:%replaced%=%all%!"
- >>"%file%_tmp.txt" echo.!str!
- )
- rem copy "%file%" "%file%_bak.conf" >nul 2>nul
- move "%file%_tmp.txt" "%file%"
- pause
复制代码 各位,最近遇到一个难题,我将SqlServer2005的表数据,使用bcp导出到一个txt文本,即为附件中的Ss.txt,然后我想替换文本中的字符串,批处理脚本如上,替换完成后,换行符没了,特请教各位,如何在替换的时候,保留换行符? |