merge many txt file contents and skip first line in batch command file

Kam picture Kam · Feb 18, 2013 · Viewed 9.2k times · Source

I want to create a Batch command file to merge text file with extension ".mf" However, each file contains date in the first line, which I donot want in the final output file, Please advice how do I get rid of the date line from each file while mergingin into one big txt file.

I have used the following command for merging the txt files for a batch file.

copy *.mf big.one
ren big.one filename.mf

Example:

2013218;
a
b
c
d

-

2013218;
u
v
w
x
y
z

The output must be like below:

2013218;
a
b
c
d
u
v
w
x
y
z

The sorting does not matter.

Answer

Aacini picture Aacini · Feb 19, 2013
@echo off
del big.one 2> NUL
for %%f in (*.mf) do (
   if not exist big.one (
      copy "%%f" big.one
   ) else (
      for /F  "usebackq skip=1 delims=" %%a in ("%%f") do (
         echo %%a>> big.one
      )
   )
)
set /P fileDate=< big.one
ren big.one filename_%fileDate:~0,-1%.mf

This solution does not preserve empty lines from second file on; this may be fixed, if needed.