Windows Notepad and Notepad++ show newlines in same file differently

18,957

Solution 1

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

Solution 2

Does the setting

Edit > EOL Conversion

Have any effect? Try switching it to UNIX.

Solution 3

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:
18,957

Related videos on Youtube

Eugene S
Author by

Eugene S

Professional Software Testing Engineer specializing in automation with Open Source tools. Interested in: Test automation: Selenium, BDD, Cucumber Programming: Java, Python, Spring Data scraping Audio: recording/mixing

Updated on September 18, 2022

Comments

  • Eugene S
    Eugene S almost 2 years

    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?

    • Admin
      Admin over 12 years
      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?
    • Admin
      Admin over 12 years
      The data is being fetched from a web site and the contents are written to a file. This is done by Perl script.
    • Admin
      Admin over 12 years
      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?
  • Eugene S
    Eugene S over 12 years
    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.
  • garyjohn
    garyjohn over 12 years
    The last line should be terminated by CRLF as well, especially if that file is going to be read by another script.
  • iglvzx
    iglvzx over 12 years
    @garyjohn Yes! I'll update my answer.
  • Taylor Styles
    Taylor Styles almost 12 years
    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.
  • Pixelmonster
    Pixelmonster almost 11 years
    Thanks, this did the job. This answer should definitely have more ups ;)