Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows batch - concatenate multiple text files into one

I need to create a script, which concatenates multiple text files into one. I know it's simple to use

type *.txt > merged.txt 

But the requirement is to "concatenate files from same day into file day_YYYY-DD-MM.txt" I am a Linux user and Windows batch is hell for me. It's Windows XP.

like image 850
SpeedEX505 Avatar asked May 26 '15 18:05

SpeedEX505


People also ask

What does %% mean in batch file?

Required. Represents a replaceable parameter. Use a single percent sign ( % ) to carry out the for command at the command prompt. Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c.


2 Answers

Windows type command works similarly to UNIX cat.

Example 1: Merge with file names (This will merge file1.csv & file2.csv to create concat.csv)

type file1.csv file2.csv > concat.csv 

Example 2: Merge files with pattern (This will merge all files with csv extension and create concat.csv)

When using asterisk(*) to concatenate all files. Please DON'T use same extension for target file(Eg. .csv). There should be some difference in pattern else target file will also be considered in concatenation

type  *.csv > concat_csv.txt 
like image 101
Shantanu Sharma Avatar answered Sep 28 '22 12:09

Shantanu Sharma


At its most basic, concatenating files from a batch file is done with 'copy'.

copy file1.txt + file2.txt + file3.txt concattedfile.txt 
like image 28
Lance Avatar answered Sep 28 '22 13:09

Lance