Concatenate multiple files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
zagix
Posts: 68
Joined: 16 Oct 2013 23:19

Concatenate multiple files

#1 Post by zagix » 20 Nov 2016 20:47

Hi,

I have 50 text files in one directory, (C:\combined). I want merge them to a single file but with one condition that to verify each file date and which is mentioned on line 2 DATE : dd/mm/yyyy. Merge all the file of Today's date only to new file c:\Real\Report.txt, and to move all those merged file to c:\backups

File format

line 1......
line 2.......................DATE : dd/mm/yyyy(aligned centre).........................User : xyz
data...
data...
data...

The structure of all the files are same and does not change.
Thanks in advance.

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Concatenate multiple files

#2 Post by SIMMS7400 » 25 Nov 2016 09:48

Some options:

Robocopy with /MAXAGE:1

Code: Select all

SET INPUT=C:\TEST
SET TEMP=C:\TEMP
SET OUTPUT=C:\Results

IF EXIST %OUTPUT%\Results.txt DEL %OUTPUT%\Results.txt
CD %INPUT%
FOR %%F IN ( *.txt ) DO (
   ROBOCOPY %INPUT% %TEMP% /MOVE /Maxage:1
   TYPE %TEMP%\%%F >> %OUTPUT%\Results.txt
   RMDIR /s /q %TEMP%
   )


Code: Select all

SET INPUT=C:\combine
SET TEMP=C:\TEMP
SET OUTPUT=C:\Results

ROBOCOPY %INPUT% %TEMP% /MOVE /Maxage:1
IF NOT EXIST %OUTPUT% MKDIR %OUTPUT%
TYPE %TEMP%\*.txt >> %OUTPUT%\Results.txt
RMDIR /s /q %TEMP%

Post Reply