Home > Blockchain >  Concatenate two text files using command line (windows) in a Batch script
Concatenate two text files using command line (windows) in a Batch script

Time:03-31

I am writing a BATCH Script using windows command prompt commands where I need to merge two text files in one of the source files: Input files:

ADAT_DZ01_20220320_104155.txt
AEDAT_DZ01_20220320_104155.txt                          

Output files:

ADAT_DZ01_20220320_104155.txt 

(Result of merging the 2 input files)

PS/ the files name changes with every extraction from the app :

ADAT_DZ01_[the changing part].txt
AEDAT_DZ01_[the changing part].txt

If you can help me out, it would be really appreciated.

copy /b ADAT*.txt AEDAT*.txt AEDAT*.txt didn't work.
more ADAT*.txt AEDAT*.txt >> ADAT*.txt also didn't work

CodePudding user response:

This batch should do the trick, feel free to adapt. Please read carefully comments within the source.

@echo off
setlocal enableextensions enabledelayedexpansion

REM Defining base prefix for both files.
set F1_PREFIX=ADAT_DZ01_
set F2_PREFIX=AEDAT_DZ01_

pushd %~dp0
REM Searching all "F1" files. No need to search for "F2".
for %%A in (           
  • Related