4

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.

David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
Kam
  • 43
  • 1
  • 1
  • 6

1 Answers1

7
@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.

Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Thankx Aacini, It worked perfectly fine. I can now save the manual work I do everyday. just a another small query regarding the file created above. I want the file to be saved as __.mf Where the date & format is same as in the first line of the file. – Kam Feb 19 '13 at 11:04
  • I have a similar process, where I have to merge many files in .txt extension. But this command does not work well. The file is created correctly, but the output file does not have extension ".txt" – Kam Aug 28 '13 at 05:57