Super User is a question and answer site for computer enthusiasts and power users. 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 created a Perl script which gets some data and inserts it line by line into a text file. When I open that file with Notepad++, it appears to have an empty line separation between each two lines of text, for example:

AAVX    Etracs Daily Short 1 Month S&P

ABCS    Guggenheim Abc High Dividend Et

ABI     Safety First Trust

However, if I open the same file with the standard Windows notepad, it appears without the spaces, as follows:

AAVX    Etracs Daily Short 1 Month S&P
ABCS    Guggenheim Abc High Dividend Et
ABI     Safety First Trust

The question is: Which one of notepads should I trust and why does it happen?

share|improve this question
    
The problem obviously is that Notepad++ interprets the Windows-typical newline CRLF as two empty lines, whereas Windows Notepad only (correctly) shows this as one line. Or similar issues. How are you creating the data? – slhck Jan 26 '12 at 17:51
    
The data is being fetched from a web site and the contents are written to a file. This is done by Perl script. – Eugene S Jan 26 '12 at 17:55
    
I would guess that somehow Notepad++ is editing in with the wrong newline mode. This might happen if CRLF's aren't used on everyline. What happens when you open it in gvim? – user606723 Jan 26 '12 at 17:58
up vote 11 down vote accepted

This happens when the EOL control characters are not correct. Windows represents newlines with the carriage return + line feed.

In Notepad++, you can check for these characters by selecting:

View > Show Symbols > [x] Show End of Line

notepad++

You need to modify your script so your data is formatted like this:

CRLF

share|improve this answer
    
Thanks! I can see now that in the end of each line there is a <CR> marker while the next line is empty and contain <CR><LF> tags. However I wonder how a script which is gonna read the file line by line will perform? I mean will it notice the empty lines or not? If yes, I will have to add some code to delete all empty lines. – Eugene S Jan 26 '12 at 18:03
1  
@EugeneS It really depends on where you run the script (e.g. a Unix vs. Windows environment). It would be best to get rid of single CR markers and stick to one consistent format. – slhck Jan 26 '12 at 18:06
1  
The last line should be terminated by CRLF as well, especially if that file is going to be read by another script. – garyjohn Jan 26 '12 at 19:14
    
@garyjohn Yes! I'll update my answer. – iglvzx Jan 26 '12 at 19:16
    
A quick fix for this issue (for those who don't have a script to create the content) is to make a macro in notepad++ (<End> <Delete> <Down>), and use the Macro -> 'Run a macro multiple times' feature to 'Run until the end of file'. This fixed it in my environment. – Darthfett Jul 11 '12 at 15:31

Does the setting

Edit > EOL Conversion

Have any effect? Try switching it to UNIX.

share|improve this answer
    
Thanks, this did the job. This answer should definitely have more ups ;) – Pixelmonster Aug 26 '13 at 2:38

You have a non-Windows EOL character in addition to the regular Windows EOL CrLf. Notepad++ understands all the various EOL characters and displays them all. Windows Notepad isn't as smart and skips the non-Windows EOL characters.

I don't know Perl but when this happens to me it is almost always because the string I'm sending has the non-Windows EOL character on the end. Test the Asc character code value of the last character in your string and strip it if it is a carriage return.

Example in VBA

If Asc(Right(sName, 1)) = 13 Then
   sName = Left(sName, Len(sName) - 1)
End If
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .