Bat replace new line char to "|"

Jerry Zhang

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 ?

Aacini
@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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

.bat Replace a char in a for loop

From Dev

Replace a "new line" char with regex in C#

From Dev

Replace a character with new line

From Dev

sed to replace comma and new line

From Dev

Replace Space with New Line in Python

From Dev

Replace string with a new line in Batch

From Dev

bash - replace space with new line

From Dev

How to replace a word with new line

From Dev

Replace string with a new line in Batch

From Dev

ASP Label Replace new line

From Dev

PhpStorm new line in HTML replace

From Dev

replace dots with new line with regex

From Dev

Create a bat file from a bat file with "%date:/=%" as line in new bat file

From Dev

Replace line in text file with a new line

From Dev

Replace line in text file with a new line

From Dev

Replace string in line without adding new line?

From Dev

Replace Multiple New Lines in One New Line

From Dev

fgets() Read New Line Char From Keyboard

From Dev

Replace new line + 4x space to new line in stdout

From Dev

How to replace a line that starts with a word (and use that old line on the new line)

From Java

Replace \n with actual new line in Sublime Text

From Dev

Replace \n(new line) with space in bash

From Dev

replace every other space with new line

From Dev

how to replace new line to empty space on coldfusion

From Dev

Using sed or VIM to replace space with new line

From Dev

How to replace a delimiter with a new line in rdlc

From Dev

Notepad++ Replace new line inside text

From Dev

How to replace New line and ^M chars with ~~ in Unix

From Dev

Replace single character in string with new line