I created a Perl script which gets some data and inserts it line by line to 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 regular Windows notepad, it seems that there are no 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?

link|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 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 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 at 17:58
feedback

3 Answers

up vote 6 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

link|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 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 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 at 19:14
@garyjohn Yes! I'll update my answer. – iglvzx Jan 26 at 19:16
feedback

Does the setting

Edit > EOL Conversion

Have any effect? Try switching it to UNIX.

link|improve this answer
feedback

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
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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