[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

bat file to merge text files

Posted on 2007-10-08
5
Medium Priority
?
8,193 Views
Last Modified: 2008-09-11
Hi,

How do I merge two text files into a single file. I am trying to write a bat script for that.

Thanks
0
Comment
Question by:chetan1981
5 Comments
 
LVL 6

Assisted Solution

by:nathana21
nathana21 earned 200 total points
ID: 20034349
0
 
LVL 23

Assisted Solution

by:Ashish Patel
Ashish Patel earned 600 total points
ID: 20034363
Use copy command in your batch file like below
Copy File1 + File2 OutputFile
0
 
LVL 3

Accepted Solution

by:
rbereny earned 1200 total points
ID: 20038613
Put either of this code in a .bat file.

This will prompt you for the three file names:
@echo off
cls
echo Please Enter the First File:
set /p file1=
set file1 2> nul

echo Please Enter the Second File:
set /p file2=
set file2 2> nul

echo Please Enter the Destination File:
set /p dest=
set dest 2> nul

type %file1% > %dest%
type %file2% >> %dest%

If you do not want a prompt but to hard code the file names use this:
@echo off
cls
set file1=h1.txt

set file2=h2.txt

set dest=new.txt

type %file1% > %dest%
type %file2% >> %dest%

0
 

Expert Comment

by:broeste
ID: 20884319
I have tried the above and gets the right output into the result file. How would you do it if you needed the out put to be presented like this in the result file??

output1/output2

I need the 2 outputs to be listed with output1/output2
0
 

Expert Comment

by:nmcllc
ID: 33561941
how would i merge a file header.txt to all *.txt files in the same directory?
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Loops Section Overview
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question