linux logfile does not open correctly in windows notepad

I have a small piece of code on my red hat linux box like

echo $ddate";"$time";"$cpu >> /home/logfile

The output is in vi

2010-04-10 12:23:32;01
2010-04-10 12:23:32;01
2010-04-10 12:23:32;01

but when i ftp this to a windows machine and open it in notepad

i see

2010-04-10 12:23:32;01 [] 2010-04-10 12:23:32;01 [] 2010-04-10 12:23:32;01

it shows me in one line and if i copy this to excel show me in different rows.

my guess is the notepad cannot understand the newline []

is there a way i can write it differently so that it can be displayed properly in notepad.


instead of notepad, try notepad++ which can handle unix linebreaks correctly without the need to modify a file. It will also keep the linebreak style when you e.g. edit config files


If you only want to view the data then something like WordPad (that usually comes with Windows) is a quick workaround & will read the LF as a new line. Things like notepad do not, for those you need LF and CR.

A better alternative is to get a windows text editor that can do much better like Notepad++


The difference between text files in Unix and Windows, is that the former use the linefeed character (\n) to terminate a line, whereas the latter use both carriage return and linefeed (\r\n). You see those squares in Notepad because the editor notices a linefeed without a preceding carriage return, and doesn't know how to display it properly.

If you first and foremost access the log file through Vim and Notepad, you should consider modifying your script to output a Windows style text file, by manually specifying what line delimiter to use:

echo -ne "$ddate;$time;$cpu\r\n"