Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!uunet!philmtl!philabs!ttidca!svirsky From: svirsky@ttidca.TTI.COM (Bill Svirsky) Newsgroups: comp.sys.ibm.pc Subject: Re: append " >> " is not working, why? (LONG) Message-ID: <6230@ttidca.TTI.COM> Date: 19 Sep 89 02:16:40 GMT References: <4734@shlump.nac.dec.com> <2553@pur-phy> Reply-To: svirsky@ttidcc.tti.com (Bill Svirsky) Organization: Citicorp/TTI, Santa Monica Lines: 114 In article <2553@pur-phy> qz@maxwell.physics.purdue.edu.UUCP (Qin Zhao) writes: + Hi, I recently got some problem when I tried to concatenate two files. +What I have done is following: + There is tow file: file1 and file2 ( I got from somebody else ). + I gave command: + type file2 >> file1 + in order to put file2 at the end of file1. And then I used "dir" to check +the size of file1, it was increased by the size of file2. +However, when I tried to read the contents of file1, I could only see the +original part of file1. I had used several editors, and "type" commands. +But when I rewrote file1 using the editor, the size of file1 drops to the +original size of file1. As has been previously mentioned, your editor is stopping at the imbedded ^Z (EOF) character. Now about concatenating files: The following is true for Compaq DOS 3.31 and IBM DOS 3.10. I believe it holds true for any DOS 3+. I'm not sure about DOS 2. The copy command in DOS makes for interesting reading. It can be used in many ways. A word of warning up front though; be *very* careful when copying files and using wildcards. You can stomp on your files. To simply concatenate text "file2" to text "file1", you can use 1) copy file1+file2 To concatenate text "file1" and text "file2" and put the results into a new file, "file3", you can use 2) copy file1+file2 file3 If you don't specify a destination file, DOS appends to the 1st file in the list. Thus, the example 1 can be extended to many more files. 3) copy file1+file2+file3+... In fact, you can use wildcards, such as 4) copy file1+file* to concatenate all files that start with "file" and have no extension to "file1". Unfortunately, DOS doesn't guarantee ascending sequence when it expands wildcards, it expands wildcards in the order that they show up in the directory. So, if a DIR displays the files in the following order: file3 file1 file2 the example 4 would have the same results as if you entered 5) copy file1+file3+file2 Well, not *exactly* the same results. Example 4 will generate 1 or more warning messages like Content of destination lost before copy What really happens is that DOS expands the command into something like 6) copy file1+file3+file1+file2 Now DOS tries not to copy a file onto itself. But it doesn't compare an input filename to the destination filename until it is ready to copy it. So, when it gets to the 2nd "file1", it then checks to make sure that the destination filename is not "file1". It not only sees that the destination file is "file1", but it thinks that the original contents of "file1" have been trashed. So it warns you. In this case DOS is wrong but, lets say you have files my.lst your.lst our.lst all of which are near and dear to you. You normally create "our.lst" by using 7) copy *.lst our.lst but in this case, you've spent hundred's of hours editing "our.lst" and just want to concatenate "my.lst" and "your.lst" to it. However, when you enter the command, your fingers betray you and enter the familiar command above. As you realize what you did, you think "No need to worry, MS-DOS won't copy a file onto itself. I'm safe". WROOOONG! DOS copies "my.lst" and "your.lst" onto "our.lst" before it gets to "our.lst" and checks to see if it is overwriting a file. It is already too late, "our.lst" is trashed, so DOS warns you. Crushed by your loss, you swear off MS-DOS (after swearing at MS-DOS), sell your PC and buy a Mac (-:. The moral of the story is; be careful using wildcards with copy. To get serious once again: You can also use wildcards with concatenation. For instance 8) copy *.h+*.c allsrc will concatenate all of your ".h" files and all of your ".c" files and place the results into "allsrc". A couple of final notes: the "/A" (ASCII) option and "/B" (BINARY) options apply only to the file immediately preceding the option and to all subsequent files until the next "/A" or "/B". "/A" is the default for concatenation, "/B" for normal copying. I hope this has all been lucid enough. It's getting late and things are getting fuzzy. I have not covered all of the COPY command, just some of the high points. You'll have to read the rest yourself. -- Bill Svirsky, Citicorp+TTI, 3100 Ocean Park Blvd., Santa Monica, CA 90405 Work phone: 213-450-9111 x2597 svirsky@ttidca.tti.com | ...!{csun,psivax,rdlvax,retix}!ttidca!svirsky