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
Solved

Use DOS to combine text files

Posted on 2014-11-15
7
434 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 69

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 53

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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
LVL 69

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 53

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

This is an article about Leadership and accepting and adapting to new challenges. It focuses mostly on upgrading to Windows 10.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
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…

860 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