In computing, a newline, also known as a line ending, end of line (EOL), or line break, is a special character or sequence of characters signifying the end of a line of text. The actual codes representing a newline vary across operating systems, which can be a problem when exchanging text files between systems with different newline representations.
The concepts of line feed (LF) and carriage return (CR) are closely associated and can be either considered separately or lumped together. In the physical media of typewriters and printers, two axes of motion, "down" and "across", are needed to create another line (a new line) on the page. Although the design of a machine (typewriter or printer) must consider them separately, the abstract logic of software can lump them together as one event. This is why a newline in character encoding can be defined as LF and CR combined into one (LF+CR, LFCR, CR+LF, CRLF).
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,'\r\n', 0x0D0A). These characters are based on printer commands: The line feed indicated that one line of paper should feed out of the printer thus instructed the printer to advance the paper one line, and a carriage return indicated that the printer carriage should return to the beginning of the current line. Some rare systems, such as QNX before version 4, used the ASCII RS (record separator, 0x1E, 30 in decimal) character as the newline character.
- LF: Multics, Unix and Unix-like systems (Linux, OS X, FreeBSD, AIX, Xenix, etc.), BeOS, Amiga, RISC OS and others.
- CR: Commodore 8-bit machines, Acorn BBC, ZX Spectrum, TRS-80, Apple II family, Mac OS up to version 9 and OS-9
- RS: QNX pre-POSIX implementation.
- 0x9B: Atari 8-bit machines using ATASCII variant of ASCII. (155 in decimal)
- LF+CR: Acorn BBC and RISC OS spooled text output.
- CR+LF: Microsoft Windows, DEC TOPS-10, RT-11 and most other early non-Unix and non-IBM OSes, CP/M, MP/M, DOS (MS-DOS, PC DOS, etc.), Atari TOS, OS/2, Symbian OS, Palm OS, Amstrad CPC
So basically the most common one :
- linux is LF (0x0a)
- windows is CRLF (0x0d 0a)
I have a text file that has CRLF line terminators (which Windows uses to terminate lines) that I want to replace with LF line terminators (the UNIX way). Notepad++ demonstrates this rather well:
If you not seeing the CRLF, you can go to view -> Show Symbols -> Show End of Line /Show all characters
Notepad++’s Find/Replace feature handles this requirement quite nicely. Simply bring up the Replace dialog (CTRL+H), select Extended search mode (ALT+X), search for “\r\n” and replace with “\n”:
Hit Replace All (ALT+A)….and job’s a good’un:
Easy when you know how!!!
Amd there turns out there’s an even easier way. From Eugene in the comments below:
Another option is to go to Edit -> EOL Conversion -> Unix Format.