Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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

share|improve this answer

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++

share|improve this answer
+1 for mentioning the quick and dirty way (WordPad) - it also handles larger files than Notepad, or at least did the last time I had to do this on Windows. – kaerast Jul 22 '10 at 10:03

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"

share|improve this answer
Please note that Vim (of course) is perfectly capable of handling both styles of line delimiters. Only Notepad is somewhat, let's say "limited"... – sleske Jul 22 '10 at 8:40

On your Linux box, run this before you ftp the file:

unix2dos /home/logfile

If you have Cygwin or a similar facility on your Windows box that provides Unix-like tools, then you could run unix2dos there after the file transfer.

By the way, this is a simplified version of your script. There's no reason to individually quote the semicolons.

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

Also, that's not the best place for the file to go. Generally, there should be no files in that directory. The place that it should go depends on several factors. I realize, however, that this may only be an example for the purposes of your question.

share|improve this answer

Check your FTP client. There should be an option to transfer the file as a text file (not binary).

In this mode it would automatically convert the linebreaks (by the way: this option can also mess up binary files such as image when you use it wrongly)

Or the unix2dos command on your linux box to convert the file to DOS/Windows linebreak format.

share|improve this answer
Note that activating conversion in your FTP client can cause a lot of hassle if you ever accidentally transfer a binary file with it and break it. IMHO it's much safer to just use a proper text editor. – sleske Jul 22 '10 at 8:41
-1 for mentioning FTP - its insecure and a PITA to manage on large systems. – symcbean Jul 22 '10 at 9:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.