Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

DOS command to combine or merge text files (Users)

posted by Rugxulo Homepage, Usono, 27.08.2012, 20:44

> The first thing I do is use REM
> to create a 0-length file with the appropriate (new) name:
>
> REM > NewFile.Ext
>
> If there are only a few files to concatenate, I use FOR at the command line
> with the COPY "+" (concatenate) feature:
>
> FOR %f IN (1,2,3,...) DO COPY NewFile.Ext+OldFile.00%f

Keep in mind that copying a zero-byte file is not consistent. I know old MS-DOS 6.2 COMMAND.COM won't copy it, but XP's CMD will! Other shells perhaps behave differently, I forget, and this breaks some (admittedly obscure, too-tricky-for-their-own-good) .BATs.

> If there are more than a few files to do this to (will require more than
> one or two FOR commands), I create a batch file to do it. I start by using
> DIR to get a sorted list of files:
>
> DIR /O /-P > DoIt.Bat

Is he sorting by file date or extension or name? Remember that pure DOS (FAT) is limited to two-second intervals, so it's not reliable if you want microsecond granularity. I know that's worrying a bit much, but it can bite.

As for sorting via DIR, that's a good idea, but again, you have to be careful. Does it sort "version" numbers correctly, e.g. ".1" comes before ".10"?? So you have to be careful. (I guess *nix "sort -n" is probably what I'm hoping for here.)

Otherwise, I guess it doesn't matter, and your solution probably mostly works (and I do similar all the time, obviously, heh).

I would almost rather just use something like REXX to generate the .BAT, but I don't guess it's good advice to say, "Download xyz to fix your problem!" Since he's using MS-DOS, it's probably idealistic (in theory) to just give him a solution in QBASIC, which I don't have right now. Just saying, in theory, use what tools are already there.

P.S. Here's a (very very rough, not totally practical) idea of what I was thinking:


#!/usr/local/bin/regina

template='file00' ; op='+' ; msg=''

do i=1 to 16
  if i = 16 then op=''
  msg = msg template || i'.txt' op
end

say 'copy' || msg || 'newfile.txt'

/*
copy file001.txt + file002.txt + file003.txt + file004.txt + file005.txt + file006.txt + file007.txt + file008.txt + file009.txt + file0010.txt + file0011.txt + file0012.txt + file0013.txt + file0014.txt + file0015.txt + file0016.txt newfile.txt
*/

 

Complete thread:

Back to the forum
Board view  Mix view
22762 Postings in 2122 Threads, 402 registered users (0 online)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum