Solved

Use DOS to combine text files

Posted on 2014-11-15
7
420 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
  • 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 68

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 51

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
Why do Marketing keep bothering you?

Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

 
LVL 68

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 51

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
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…
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.

746 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

12 Experts available now in Live!

Get 1:1 Help Now