5

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?

3
  • 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
    Commented Jan 26, 2012 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
    Commented Jan 26, 2012 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
    Commented Jan 26, 2012 at 17:58

3 Answers 3

11

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

5
  • 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
    Commented Jan 26, 2012 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
    Commented Jan 26, 2012 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
    Commented Jan 26, 2012 at 19:14
  • @garyjohn Yes! I'll update my answer.
    – iglvzx
    Commented Jan 26, 2012 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. Commented Jul 11, 2012 at 15:31
4

Does the setting

Edit > EOL Conversion

Have any effect? Try switching it to UNIX.

1
  • Thanks, this did the job. This answer should definitely have more ups ;) Commented Aug 26, 2013 at 2:38
2

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

You must log in to answer this question.

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