Solved

Use DOS to combine text files

Posted on 2014-11-15
7
455 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 250 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 70

Assisted Solution

by:Qlemo
Qlemo earned 250 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 56

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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 70

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 56

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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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…
Suggested Courses

628 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