?
Solved

Merge files

Posted on 2006-05-03
5
Medium Priority
?
1,747 Views
Last Modified: 2007-12-19
Hi Everyone,

I want to add to add 2 files in 1. But sometimes this first file won't have a carriage return/line feed an this wont merge the files properly. Here's an example.

File 1:
1111
2222(no carriage return)

File 2:
3333
4444

With a copy 1 + 2 result, I'll have something like:
1111
22223333
4444

And I just want 1 row per line, This because the file "1" sometimes doesn't have the carriage return, do you know a command or a way to check if the carriage return ir missing?

Thanks!
0
Comment
Question by:amphill
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16601331
hi,
you may try this (if you have no problems to have empty rows in your result file sometimes)
create file cr.txt in which you put just one carriage return/line feed
and create a bat file with these commands

type 1 > 3
type cr.txt > 3
type 2 >> 3

this will create file 3 with the content of 1
add the CR/LF symbols from cr.txt to 3
after that add the content of 2 to 3
0
 
LVL 11

Expert Comment

by:WelkinMaze
ID: 16601356
oops,
this row (type cr.txt > 3) has to be
type cr.txt >> 3
0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 320 total points
ID: 16602569
You could do the following:

@echo off

setlocal

REM ** Input files
set file1=temp1.txt
set file2=temp2.txt

REM ** Output file
set file3=temp3.txt

if exist "%file3%" del "%file3%"

for %%a in ("%file1%", "%file2%") do (
  for /f "delims=" %%b in ('type "%%a" 2^>NUL') do (echo %%b)>>"%file3%"
)

echo Output in %file3%

Feel free to change file1, file2, and file3.

Good Luck,
Steve
0
 

Author Comment

by:amphill
ID: 16602652
Thsnk for the answer WelkinMaze, bu in this case there will be no emtpy rows, anyway, it's a good idea.
0
 

Author Comment

by:amphill
ID: 16602662
SteveGTR ... wow... that was fast and precise.
That's exactly what I needed, this is the first time that I use batch files (ms-dos basis) and I will try to comprehend your batch.

Thanks for this great answer, accepted.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 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