Find the answer to your Linux question:
Results 1 to 9 of 9
Hi, I've been developing in PHP for a few years and I've noticed that a file that I created in vi editor using SSH on my linux server, when viewed ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2008
    Posts
    21

    New line character in windows and linux


    Hi,

    I've been developing in PHP for a few years and I've noticed that a file that I created in vi editor using SSH on my linux server, when viewed with notepad wasnt displaying properly. I noticed the same thing happen in a few other instances. Why is that?

    What is the ascii number of a new line character in windows and linux?

    Raja Sekharan

  2. #2
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    UNIX/Linux uses a newline character (\n, decimal 12) as a line terminator, Windoze uses carriage-return newline pairs (\r\n decimal 15, 12). You can use dos2unix and unix2dos to switch formats, but it's Windows that is out of step by using 2 characters as a line terminator instead of a more sensible single one, and since UNIX specified that character back in the early 70s, it can only be bloody-mindedness on Bill Gates' part that he deliberately chose to be incompatible.

  3. #3
    Just Joined!
    Join Date
    Jan 2008
    Posts
    21
    Ok but, in notepad, atleast the '\n' should be rendered right? All i saw as a continuous wall of code with "box"y characters where the line breaks were supposed to be. When you try to delete those characters, notepad seems to misbehave.

  4. #4
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,134
    Different editors handle this differently, with some seemingly able
    to handle both formats. There are lots of free replacements for
    notepad, and some of them may be better with line feeds.

    For the historical record, the CR/LF two character line ending is
    the original ascii standard that predates both unix and microsoft,
    and it was unix that departed from the standard.

  5. #5
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    Quote Originally Posted by scm View Post
    UNIX/Linux uses a newline character (\n, decimal 12) as a line terminator, Windoze uses carriage-return newline pairs (\r\n decimal 15, 12). You can use dos2unix and unix2dos to switch formats, but it's Windows that is out of step by using 2 characters as a line terminator instead of a more sensible single one, and since UNIX specified that character back in the early 70s, it can only be bloody-mindedness on Bill Gates' part that he deliberately chose to be incompatible.
    The ascii code for the newline character in Unix/Linux is

    0A = decimal 10

    and Dos and Windows (newline characters):

    0D = decimal 13
    0A = decimal 10

    Regards

  6. #6
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    D'oh, old habits die hard!
    :%s/decimal/octal/g

  7. #7
    Linux Engineer
    Join Date
    Nov 2004
    Location
    home
    Posts
    796
    You can use wordpad on windows, it handles \n properly.

  8. #8
    Just Joined! lajevardi's Avatar
    Join Date
    May 2008
    Posts
    1
    I'm using a single todo file synchronized within Ubuntu Gutsy and Windows xp.
    gedit uses LF line ending as other linux editors does, and I'm using Notepad2 instead of Notepad to handle LF instead of CR line endings.
    Notepad2 has an option to choose line endings character.
    Notepad++ is another choice.

  9. #9
    Just Joined!
    Join Date
    May 2008
    Location
    ┼snorrbodarna
    Posts
    8
    If you're using vim (which I believe is the case in most Linux distros) you can also do :set ff=dos (or :set fileformat=dos) to make it use CR+LF instead of just LF for line breaks. You can add the setting to your .vimrc file if you want it for all files (or certain file types).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •