Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use DOS to combine text files

Posted on 2014-11-15
7
Medium Priority
?
471 Views
Last Modified: 2014-11-16
This is a two part question.  I am performing some data mining
routines for a client who has provided the following system
configuration:

Windows 7-64Bit
8Gig of Ram
Monarch v 10.5
Office 2007

Part 1:
I have several text files that I am combining with the following
name structure:
"xxxx xx xxxxxx.txt"

Within a batch file I issued the following command line:
COPY *.Txt "H13P46 LDistrb YTD.Txt"
This command works fine but select files within the combined file
are rejected by Monarch as exceeding "4000 character line"
None of the lines are greater than 256 characters - not sure what is causing
the error.  Combine works fine except Monarch cannot read it.

However, Monarch can read each individual file without any problems.

==============================================================================
Part II:
To alleviate the problem above I tried combining the text files as follows:
For %%F in (*.txt) do type %%F >> Output.txt

If I copy the command from within DOS it works fine; AND Monarch has no
problem reading the resultant combined file.
If I try running it from within the batch file it fails to combine the files
because it does not recognize the file name: xxxx xx xxxxxx.txt;
the DOS error states it is looking for only the xxxxxx.txt portion of the name.
I have tried various items such as double/single quotation marks and still no
result.

My goal is to combine multiple text files into one text file and then proceed to
run multiple Monarch routines from within the Monarch Scripting.
0
Comment
Question by:Wildbi11
[X]
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
  • +1
7 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1000 total points
ID: 40444991
Just passing... but try this... use ' ' around a command to read it's output for the for command, and redirect them all in one go using ( ) around for then directing that to file with >

Steve

@Echo off
cd /d c:\startdir
(For %%F in ('dir /b /a-d *.txt') do type %%F )> c:\outputdir\Output.txt

Open in new window


or

cd /d c:\startdir
type *.txt > c:\outputdir\output.txt

Open in new window


etc.
0
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 1000 total points
ID: 40445025
The FOR is missing some important stuff, but the second snippet should work fine.
The first would have to look like:
@echo off
cd /d c:\startdir
(for /F "delims=" %%F in ('dir /b /a:-d *.txt') do type "%%~F") > c:\outputdir\Output.txt

Open in new window

Because of the spaces, the file name needs to be double quotes all the time.
In fact, your original loop was almost correct. Translated into the environment as posted by Steve:
@echo off
cd /d c:\startdir
(for %%F in (*.txt) do type "%%~F") > c:\outputdir\Output.txt

Open in new window

0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 40445051
If you can provide a sample of the individual files, and the COPY *.* output file that reports more than 4000 characters in a line, I'd be interested in looking at those for the potential cause.

~bp
0
Industry Leaders: 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 71

Expert Comment

by:Qlemo
ID: 40445056
Bill,
I suppose COPY does not forcefully add a line break for the last line (nor an EOF) of each file, and so lines might get concatenated. But just a guess.
0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 40445057
Understand Clemo, but I don't think the original files had lines near 2000, so that felt like it might not be the issue.  I thought maybe unix EOL perhaps, but wanted to check out the files in hex to look for anything interesting.  I know you can relate.

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40445066
Oops, yes a /F missed there in http:#a40444991 as Qlemo pointed out, said was quick passing comment!

Steve
0
 

Author Closing Comment

by:Wildbi11
ID: 40446023
Thanks for the help - you were quick with an answer and "right on" with the solution.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

660 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