Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Misc
Reload this Page New line character in windows and linux
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Misc Any questions or Linux discussion that does not fit in any of the other technical areas.

Reply
 
Thread Tools Display Modes
Old 01-12-2008   #1 (permalink)
rajasekharan
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
rajasekharan is offline   Reply With Quote
Old 01-12-2008   #2 (permalink)
scm
Linux Engineer
 
Join Date: Feb 2005
Posts: 924
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.
scm is offline   Reply With Quote
Old 01-12-2008   #3 (permalink)
rajasekharan
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.
rajasekharan is offline   Reply With Quote
Old 01-12-2008   #4 (permalink)
rcgreen
Linux Enthusiast
 
rcgreen's Avatar
 
Join Date: May 2006
Location: the hills
Posts: 507
Send a message via Yahoo to rcgreen
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.
rcgreen is offline   Reply With Quote
Old 01-12-2008   #5 (permalink)
Franklin52
Linux Enthusiast
 
Franklin52's Avatar
 
Join Date: Aug 2006
Posts: 596
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
Franklin52 is offline   Reply With Quote
Old 01-13-2008   #6 (permalink)
scm
Linux Engineer
 
Join Date: Feb 2005
Posts: 924
D'oh, old habits die hard!
:%s/decimal/octal/g
scm is offline   Reply With Quote
Old 01-13-2008   #7 (permalink)
valan
Linux Engineer
 
Join Date: Nov 2004
Posts: 785
You can use wordpad on windows, it handles \n properly.
valan is offline   Reply With Quote
Old 05-11-2008   #8 (permalink)
lajevardi
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.
lajevardi is offline   Reply With Quote
Old 05-13-2008   #9 (permalink)
AutisticCuckoo
Just Joined!
 
Join Date: May 2008
Location: Åsnorrbodarna
Posts: 5
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).
__________________
Tommy OlssonThe Autistic Cuckoo
AutisticCuckoo is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SATA and IDE Disks - How To (By Request) PT I jimc52 Installation 1 03-06-2007 01:12 AM


All times are GMT. The time now is 12:44 AM.

Powered by vBulletin 3.6.8 ©2000 - 2007, content relevant URLs by vBSEO, Property of Core Root.

Content Relevant URLs by vBSEO 3.0.0