我想将新行字符替换为"|" 使用Window bat.
例如file1:
1
2
3
Run Code Online (Sandbox Code Playgroud)
输出:
1|2|3
Run Code Online (Sandbox Code Playgroud)
我试试这个蝙蝠:
echo off
setlocal enabledelayedexpansion
for /f "delims=" %%a in (123.txt) do (
set a=%%a
set a=!a:"\r\n"=^|!
for %%b in ("!a!") do (
echo.%%~b>>1245.txt
))
pause
Run Code Online (Sandbox Code Playgroud)
但是,新行char不是"\ r \n".如何获取新的行char表达式?
@echo off
setlocal EnableDelayedExpansion
rem Initialize the output line
set "line="
rem Catenate all file lines in the same variable separated by "|"
for /F "delims=" %%a in (123.txt) do set "line=!line!|%%a"
rem Show final line, removing the leading "|"
echo !line:~1!>>1245.txt
Run Code Online (Sandbox Code Playgroud)