Merge 4 text files

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Merge 4 text files

Post by Michael Abrams »

I receive 4 text files with data - all have the same specs (delimited)
I must merge all 4 into one main text file.

Currently I open each one, copy, and paste the data into the main text file.

Is there a way to automate this process? Macro, batch file? It is a real pain (and possible data integrity issue if all
data is not copied into the main one).

Thank you.

Michael

User avatar
HansV
Administrator
Posts: 78405
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Merge 4 text files

Post by HansV »

Do the text files have a header row/line?
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Merge 4 text files

Post by Michael Abrams »

Just data.

No header, footer, trailer.

Thanks HansV !

Michael

User avatar
HansV
Administrator
Posts: 78405
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Merge 4 text files

Post by HansV »

You could use a batch file with the following contents:

@echo off
cd c:\textfiles
copy oldfile.txt+file1.txt+file2.txt+file3.txt+file4.txt newfile.txt
del oldfile.txt
ren newfile.txt oldfile.txt

This merges file1.txt ... file4.txt into oldfile.txt in a folder c:\textfiles.

Make a backup copy before trying it!
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Merge 4 text files

Post by Michael Abrams »

Now I can't wait to go to work tomorrow and try it!

Thanks a million Hans !!

Michael