DOS Concatination of Files

In DOS there are several useful commands that we can use to combine files into one file. In order to do this we will make use of the redirection operators (which are also in UNIX) to move data around. You will recall that the type command in DOS will read a file and send its contents to the screen. For example the command type file.txt will display the contents on the screen.

Note closely what happens in each case of the above execution. The first command I do is type data.txt. It just prints out the contents of this file which is just two lines. The next command is type data2.txt and it does the same. The next command is the interesting one.

type data.txt>out.txt

This command uses the redirection operator > to redirect the output, which normally goes to the screen, to the file out.txt. It will create the file for you. The next command

type data2.txt>> out.txt

uses the concatenation operator >> which is used to add new data to the bottom of an existing file. In this case we combine data.txt and data2.txt into one file called out.txt. Note that when I type out.txt we get the entire statement.


How to combine source and execution output

This is very similar to the above method. We of course start with a program that we are running say

In order to run the program we do something like C:\perl and the output will go to the screen. The following will combine the output with the program source.

  • type>printout.txt #this puts your program into printout.txt
  • perl>>printout.txt #this adds the output to the end of printout.txt
  • type printout.txt #this prints it all

NOTE: the above method does have a problem. If the program you run, say has interactive input, the prompts go to the file and not to the screen. The means the user doesn’t know what to type. This works better when the program is just a “filter”. Filters are programs that read data, modify it and print it out without user input.

You could just run the program in DOS and copy the command sequence and then paste and printout at the bottom of the program in Notepad.

Comments are closed.