- 1 year ago
Replacing the sequence \r\r\n with the \r\n in batch file
Comment
1 / 1
In a batch file, you can use the findstr
command with regular expressions to replace the sequence \r\r\n
with \r\n
. Here's an example:
batch@echo off
setlocal enabledelayedexpansion
set "inputFile=input.txt"
set "outputFile=output.txt"
for /f "delims=" %%a in ('type "%inputFile%" ^| findstr /r /n "^"') do (
set "line=%%a"
setlocal enabledelayedexpansion
echo(!line:*:=! | findstr /r "^[\r][\r][\n]$">nul
if not errorlevel 1 (
echo(\r\n>>"%outputFile%"
) else (
echo(!line:*:=!>>"%outputFile%"
)
endlocal
)
echo "Replacement complete."
This script reads the contents of the inputFile
line by line and checks if each line matches the pattern [\r][\r][\n]
. If it matches, it replaces it with \r\n
in the outputFile
. Otherwise, it copies the line as is. The output is saved to the outputFile
.
Make sure to replace input.txt
with the path to your input file, and output.txt
with the desired output file.
Note that this script is case-sensitive. If you need a case-insensitive search, you can add the /i
option to the findstr
command:
batchecho(!line:*:=! | findstr /r /i "^[\r][\r][\n]$">nul
After running the batch file, you should find that the \r\r\n
sequence has been replaced with \r\n
in the output file.