Solved

How can I join two or more text files together

Posted on 2014-10-30
6
130 Views
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.
0
Comment
Question by:100questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 10

Accepted Solution

by:
JoeKlimis earned 500 total points
ID: 40413528
Hi
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

0
 
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"
 echo.
)) > outfile.txt

Open in new window

Steve
0
 

Author Comment

by:100questions
ID: 40413595
@JoeKlimis - Thanks Joe, this works well.  How would I specify the path of each input file.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 10

Expert Comment

by:JoeKlimis
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

0
 

Author Closing Comment

by:100questions
ID: 40413850
Excellent, works well.
0
 
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?
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

775 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