How can I join two or more text files together

Posted on 2014-10-30
Medium Priority
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 2000 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.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

719 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