In computing, a newline , also known as a line break or end-of-line ( EOL ) character, is a special character or sequence of characters signifying the end of a line of text. The name comes from the fact that the next character after the newline will appear on a new line —that is, on the next line below the text immediately preceding the newline. The actual codes representing a newline vary across operating systems, which can be a problem when exchanging data between systems with different representations.

There is also some confusion whether newlines terminate or separate lines. If a newline is considered a separator, there will be no newline after the last line of a file. The general convention on most systems is to add a newline even after the last line, i.e., to treat newline as a line terminator. Some programs have problems processing the last line of a file if it is not newline terminated. Conversely, programs that expect newline to be used as a separator will interpret a final newline as starting a new (empty) line.

In text intended primarily to be read by humans using software which implements the word wrap feature, a newline character typically only needs to be stored if a line break is required independent of whether the next word would fit on the same line, such as between paragraphs and in vertical lists. See hard return and soft return.

Representations

Software applications and operating systems usually represent a newline with one or two control characters:

  • Systems based on ASCII or a compatible character set use either LF (Line feed, '\n', 0x0A , 10 in decimal) or CR (Carriage return, '\r', 0x0D , 13 in decimal) individually, or CR followed by LF ( CR + LF , 0x0D 0x0A ). These characters are based on printer commands: The line feed indicated that one line of paper should feed out of the printer, and a carriage return indicated that the printer carriage should return to the beginning of the current line.
    • LF :     Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others
    • CR + LF : DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS
    • CR :     Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9
  • EBCDIC systems—mainly IBM mainframe systems, including z/OS (OS/390) and i5/OS (OS/400)—use NEL (Next Line, 0x15) as the newline character. Note that EBCDIC also has control characters called CR and LF , but the numerical value of LF (0x25) differs from the one used by ASCII (0x0A). Additionally, there are some EBCDIC variants that also use NEL but assign a different numeric code to the character.
  • Operating systems for the CDC 6000 series defined a newline as two or more zero-valued six-bit characters at the end of a 60-bit word. Some configurations also defined a zero-valued character as a colon character, with the result that multiple colons could be interpreted as a newline depending on position.
  • Many older systems stored the characters for each line in a separate "record". There was thus no line terminator character.
    • Many old mainframe operating systems added a carriage control character to the start of the next record, this could indicate if the next record was a continuation of the line started by the previous record, or a new line, or should overprint the previous line (similar to a CR). Often this was a normal printing character such as '#' that thus could not be used as the first character in a line. Some early line printers interpreted these characters directly in the records sent to them.
    • OpenVMS uses a record-based file system, which stores text files as one record per line. In most file formats, no line terminators are actually stored, but the Record Management Services facility can transparently add a terminator to each line when it is retrieved by an application.
    • Fixed line length was used by some early mainframe operating systems. In such a system, an implicit end-of-line was assumed every 80 characters, for example. No newline character was stored. If a file was imported from the outside world, lines shorter than the line length had to be padded with spaces, while lines longer than the line length had to be truncated. This mimicked the use of punched cards, on which each line was stored on a separate card, usually with 80 columns on each card.

Most textual Internet protocols (including HTTP, SMTP, FTP, IRC and many others) mandate the use of ASCII CR + LF ( 0x0D 0x0A ) on the protocol level, but recommend that tolerant applications recognize lone LF as well. In practice, there are many applications that erroneously use the C newline character '\n' instead (see section Newline in programming languages below). This leads to problems when trying to communicate with systems adhering to a stricter interpretation of the standards; one such system is the qmail MTA that actively refuses to accept messages from systems that send bare LF instead of the required CR + LF .

Unicode

The Unicode standard defines a large number of characters that conforming applications should recognize as line terminators:

 LF :     Line Feed, U+000A
 CR :     Carriage Return, U+000D
 CR + LF : CR ( U+000D ) followed by LF ( U+000A )
 NEL :    Next Line, U+0085
 FF :     Form Feed, U+000C
 LS :     Line Separator, U+2028
 PS :     Paragraph Separator, U+2029

This may seem overly complicated compared to an approach such as converting all line terminators to a single character, for example LF . However Unicode was designed to preserve all information when converting a text file from any existing encoding, including EBCDIC, to Unicode and back. When converting to Unicode, NEL would have to be replaced by LF , but when converting back it would be impossible to decide if an LF should be mapped to an EBCDIC LF or NEL . The approach taken in the Unicode standard allows round-trip transformation to be information-preserving while still enabling applications to recognize all possible types of line terminators.

Handling characters greater than 0x7F is often impractical or incompatible and is not often done. This is because they are multiple bytes in UTF-8 and the code for NEL has been used as the ellipsis ('…') character in Windows-1252. For instance YAML has dropped support for these in order to be compatible with JSON.

History

ASCII was developed simultaneously by the ISO and the ASA, the predecessor organization to ANSI. During the period of 1963–1968, the ISO draft standards supported the use of either CR + LF or LF alone as a newline, while the ASA drafts supported only CR + LF . The Multics operating system began development in 1964 and used LF alone as its newline. Unix followed the Multics practice, and later systems followed Unix.

The sequence CR + LF was in common use on many early computer systems that had adopted teletype machines, typically an ASR33, as a console device, because this sequence was required to position those printers at the start of a new line. On these systems, text was often routinely composed to be compatible with these printers, since the concept of device drivers hiding such hardware details from the application was not yet well developed; applications had to talk directly to the teletype machine and follow its conventions.

The separation of the two functions concealed the fact that the print head could not return from the far right to the beginning of the next line in one-character time. That is why the sequence was always sent with the CR first. In fact, it was often necessary to send extra characters (extraneous CRs or NULs, which are ignored) to give the print head time to move to the left margin.

Even after teletypes were replaced by computer terminals with higher baud rates, many operating systems still supported automatic sending of these fill characters, for compatibility with cheaper terminals that required multiple character times to scroll the display.

MS-DOS adopted CP/M's CR + LF ; CP/M's use of CR + LF made sense for using computer terminals via serial lines. This convention was inherited by Microsoft's later Windows operating system.

In programming languages

To facilitate the creation of portable programs, programming languages provide some abstractions to deal with the different types of newline sequences used in different environments.

The C programming language provides the escape sequences '\n' (newline) and '\r' (carriage return). However, these are not required to be equivalent to the ASCII LF and CR control characters. The C standard only guarantees two things:

  1. Each of these escape sequences maps to a uniqu

    Newline - Wikipedia, the free encyclopedia

    In computing, a newline, also known as a line break or end-of-line (EOL) character, is a special character or sequence of characters signifying the end of a line of text.

    ...

    line feed from FOLDOC

    LF ==>line feed < character > (LF, control-J, ASCII 10) The ASCII character meaning move the cursor down to the same column on the next line. Originally this would have been done by ...

    ...

    Feed line - Wikipedia, the free encyclopedia

    The Feed line in a radio transmission, reception or transceiver system is the physical cabling that carries the RF signal to and/or from the antenna.

    ...

    line feed - Computer Definition

    (1) A character code that advances the screen cursor or printer to the next line. The line feed is used as an end-of-line code in Unix. In Windows, DOS and OS/2 text files, the ...

    ...

    Newline - Simple English Wikipedia, the free ...

    Line feed is the name of a computer character that directs a printer or screen display to advance one line of text. The word "feed" refers to it's original use: causing paper to be ...

    ...

    Amazon.com: "Line Feed": Key Phrase page

    Key Phrase page for Line Feed: Books containing the phrase Line Feed

    ...

    Line Feed [DOWNLOAD OUR FIRST DEMO FOR FREE!!] on ...

    MySpace Music profile for Line Feed [DOWNLOAD OUR FIRST DEMO FOR FREE!!]. Download Line Feed [DOWNLOAD OUR FIRST DEMO FOR FREE!!] Hardcore / Metal / Zouk music singles, watch music ...

    ...

    line feed characters

    Posts: 1 Joined: 4/30/2007 Status: offline: Hi, We are transfering via SSH (port 22) from CuteFTP 80 to a VanDyke SSH server running Win 2003. The recieved file has line feed ...

    ...

    Line feed | Define Line feed at Dictionary.com

    Copy & paste this link to your blog or website to reference this page

    ...

    Words related to "line_feed" - OneLook Dictionary ...

    Words and phrases matching your pattern: (We're restricting the list to terms we think are related to line feed, and sorting by relatedness.)

    ...