- 1 year ago
How to merge file in to one with "enter"(New line) in windows batch file?
Comment
1 / 1
To merge multiple files into one with a newline (Enter) between each file's content using a Windows batch file, you can use the type
command along with the output redirection (>>
). Here's an example:
batch@echo off
set "outputFile=merged.txt"
:: Clear the output file if it exists
if exist "%outputFile%" del "%outputFile%"
:: Loop through each file and append its content to the output file
for %%f in (file1.txt file2.txt file3.txt) do (
type "%%f" >> "%outputFile%"
echo. >> "%outputFile%"
)
echo Merging completed.
Replace file1.txt
, file2.txt
, and file3.txt
with the actual file names you want to merge. The echo.
statement is used to add an empty line (newline) between each file's content.
This script will create an outputFile
named merged.txt
in the same directory as the batch file. The script clears the output file if it already exists and then appends the content of each specified file followed by an empty line.
You can adjust the file names and the outputFile
variable according to your needs.