I want to replace new line char to "|" use Window bat.
eg file1:
1
2
3
output:
1|2|3
I try this 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
But, new line char is not "\r\n". How can I get the new line char expression ?
@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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With