Solved

How to combine txt files and change .txt extension

Posted on 2016-09-22
7
52 Views
Last Modified: 2016-09-23
I have multiple .txt files in one folder. Each .txt file has a few rows of data. How would I create a batch file that will combine the rows on all the text files into one .txt file. So if there are 5 .txt files and 2 rows in each of those text files, the new .txt file would have 10 rows of data. Also, when this new file is created, I need the file extension to be ".tra". The file name can be "TR2016" Is there a way to do this? Thanks!
0
Comment
Question by:brasiman
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:NVIT
ID: 41811538
Note: You have not specified if the files must be output in a certain order. e.g. file1.txt, file2.txt, etc. If so, code must be revised.

Make a .bat file of this.
Change FNSrcPatt, and FNOut values per your needs.

@echo off
setlocal enabledelayedexpansion

set FNSrcPatt=c:\local\test\*.txt
set FNOut=TR2016.tra
for %%a in ("%FNSrcPatt%") do (type %%a>>"%FNOut%")

Open in new window

0
 

Author Comment

by:brasiman
ID: 41812572
Thank you NVIT! This is perfect! One thing I forgot to ask, what if I want to move the .tra file to a different location? So the .txt files are in c:\folder and i want to create the .tra file in the c:\TRA_Files.
0
 
LVL 23

Accepted Solution

by:
NVIT earned 500 total points
ID: 41812639
@echo off
setlocal enabledelayedexpansion

set FNSrcPatt=c:\folder\*.txt
set FNOut=c:\TRA_Files\TR2016.tra
for %%a in ("%FNSrcPatt%") do (type %%a>>"%FNOut%")

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:brasiman
ID: 41813134
NVIT, thats perfect. Thank. I just ran into the last thing with this. And if i need to start another question I can. When I run this, the old .txt files are left behind in c:\folder\. Is there a way, keeping the script as is, just adding a way for me to specify a folder that those .txt files are put...and have a folder created with it date and time stamped? So, using what you suggested, but then adding code where I specify where to create a new folder, the title of the folder is the current date and time, then the .txt files are moved to the newly created folder. Does that make sense? Thanks!
0
 
LVL 23

Expert Comment

by:NVIT
ID: 41813149
Hi brasiman.

Please close this question. I'll help you with the next one. In that one, add a link to this page.
0
 

Author Comment

by:brasiman
ID: 41813157
Hi NVIT, I'll close this one now. Here's the link to the new question:
https://www.experts-exchange.com/questions/28972004/How-to-combine-txt-and-create-a-new-folder.html
0
 

Author Closing Comment

by:brasiman
ID: 41813160
Perfect! Replied quickly. Thanks!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now