.bat or .pl script help

hi
I need to rediret an content of one file and append it to another file. I need it in .bat script. I tried this,

first.txt
I love to write script

type first.txt >> out.txt
type first.txt >> out.txt

out.txt
I love to write scriptI love to write script

you see the second append go in the same line.I need to print the second append to go in the next line.Like this

I love to write script
I love to write script

Can oneone help me.

also let me know the perl coding for this.

thanks...
Gopal

I'm sad to have to say this, but this sounds like homework. Homework is forbidden here, as there is a special forum for it, with special rules in place. Furthermore, this seems to deal with a DOS/Windows problem for which there is also another forum.

As you have undertaken a serious effort to solve your problem yourself and shown it i will make an exception to the rule ad answer, but PLEASE DO NOT TAKE THIS AS AN INVITATION to further stretch the rules.

first.txt 
I love to write script
type first.txt >> out.txt
type first.txt >> out.txt

out.txt

I love to write scriptI love to write script

The reason for this behavior is not your script but your input file: you omitted the last linefeed after the end-of-file marker. Open your file "first.txt", got to the end of the line and press <ENTER>, then save the file. You will notice that your script will now work.

Here is some explanation: a file consists not only of readable ("printable" - which means also printable to the screen) characters and blanks, but also special characters used to transport some steering information. One of these special characters (or character combinations) is the "EOF", the "end-of-file"-marker, which has to be at the end of every file. In Unix this is a "^D" (CTRL-D) character, in DOS, Windows (and, historically, in CP/M) this is a "^Z" (CTRL-Z). See this reference for more information. The same is the case for the end of a line: Your computer has to somehow discern between

one linesecond line

and

one line
second line

and this is done by inserting a special character which does exactly that. In DOS/Windows this is in fact a character combination, "CR/LF" ("Carriage Return", followed by a "Line Feed") with the hex codes "0D 0A". In Unix this is simply a "Line feed" character (hex "0A").

Btw: This difference is why there is a "binary" and a "text" mode in ftp: "text mode" would mean to translate "0D0A" to "0A" when transferring a file from a Unix system to/from a DOS system, "binary mode" means to not do this translation.

See this wikipedia article for more information about "Newline".

However, if you would display your file "first.txt" including these non-printable characters (use a hex-editor or "od" on a Unix-system) you would see:

f i r s t   l i n e ^Z

When you "type" that two time into another file, the following happens: first the EOF character is removed, then the remainder is copied to the empty output file, then a EOF character is appended to the output. Then the second file is read, the EOF character of it is removed, text is appended to the output file and an EOF character is appended again. By now you have what you got with your script.

If the file would have contained an EOL character it would now contain "text<EOL>text<EOL><EOF>" and this would look like your desired output.

I hope this helps to understand.

bakunin

-closed-