How can I join two or more text files together

Posted on 2014-10-30
Last Modified: 2014-10-30
I would like to join two or more text files together however I need to ensure there is a blank line between the data which was found in each file.
Question by:100questions
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
LVL 11

Accepted Solution

Joe Klimis earned 500 total points
ID: 40413528
This is a powershell solution

where data.txt and data1.txt are the two files to be joined into the results file r.txt

  $(gc data.txt)  +"`n "+ $(gc data1.txt) | Out-File r.txt

Open in new window

LVL 43

Expert Comment

by:Steve Knight
ID: 40413581
In batch one way would be something like this - will take all .txt files in c:\yourdir:

@echo off
cd /d "c:\yourdir"
(for /f %%a in ('dir /b /a-d *.txt') do (
 type "%%~a"
)) > outfile.txt

Open in new window


Author Comment

ID: 40413595
@JoeKlimis - Thanks Joe, this works well.  How would I specify the path of each input file.
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

LVL 11

Expert Comment

by:Joe Klimis
ID: 40413639
I have included the file paths

$(gc c:\temp\data.txt)  +"`n "+ $(gc d:\temp2\data1.txt) | Out-File e:\temp3\r.txt

Open in new window

you can always use wildcards too (*) as follows

$(gc c:\temp\data*.txt)  +"`n "+ $(gc d:\temp2\A*.txt) | Out-File e:\temp3\r.txt

Open in new window


Author Closing Comment

ID: 40413850
Excellent, works well.
LVL 43

Expert Comment

by:Steve Knight
ID: 40413911
Could you post in area relating to language wanted only another time please to save wasting time?

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

636 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