我想将新行字符替换为“|”使用Window bat。
例如file1:
1
2
3
输出:
1|2|3
我试试这个 bat :
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
但是,换行符不是“\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
关于batch-file - bat 替换新行char到 "|",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26881839/