\n\r of line breaks and use of TXT and Word documents under Linux __linux

Source: Internet
Author: User

Documents written in Notepad under Windows are different from those written under Linux, Vim, or gedit.

For example, the SH script written under Windows can be executed under Linux for error.

Workaround:

The reason is: Windows newline symbol is "\ r \ n", and Linux is "\ n" no "\ R", when the shell file is written in Windows, all line breaks are "\ r \ n", the shell is not able to execute this file, will prompt the above error. Please execute the file "File->conversions->dos to Unix" under UltraEdit and execute the transformed SH file directly under Linux. This can be done by canceling the "\ r" symbol.

You can choose ASCII on the client side.

If you've already finished transfer with binary, try this:

Cat Ms.txt | Col-b > Linux.txt

New documents under Linux are jammed together (without line breaks) under Windows with Notepad, because Notepad does not support \ n line wrapping (it only supports \ r),

Workaround:

Save the DOC format in Word, so you can use Vim or gedit in Linux to create a new doc document (which is a plain doc document) (or a newly built. c document that you can browse with VC6.0 in Windows.) )。 To open the command can also be entered directly: (Note that if the filename is Chinese, it may not be found, need LS, and then copy the filename, and then gedit paste the file name)

Gedit Xx.doc

or Vim Xx.doc (not recommended, VIM may not support traditional characters)

or directly find the file, click, Open Office, select the character set (System), character (SYSong18030), language (Simplified Chinese), change paragraph:

1. Cr&lf, that is, \ r \ n, this is the format of Windows Notepad, Linux is fully supported; (recommended)

2. CR, that is, \ r, Notepad is not supported, no line wrapping effect, there is no \ r effect; Word has a newline effect, or \ r, with a \ R effect: At the end of each line, the default cursor position is the beginning of the next line, which means that what you enter at the end of the line is actually the beginning of the next row, and \ r is the real line and \ n is a carriage return, the paper originally intended to move the typewriter down a bit, and later, under the Linux/unix system, \ n became the actual line feed.

3. LF, that is, the line break under the \n,linux/unix system.

If you are a doc document written under Windows, it is generally garbled to view it under Linux (with open Office).

Workaround:

Open the first, and then select All, set the font to Sysong18030,ok Chinese Simplified and traditional are displayed normal.

\ r is a carriage return, \ n is a newline character, and a newline flag for each system:

Win with \ r \ n

Linux/unix with \ n

Mac OS with \ r

CR uses the symbol ' \ R ' to indicate that the decimal ASCII code is 13 and the hexadecimal code is OXOD

LF using ' \ n ' notation, ASCII code is 10, 16 is 0x0a

So Windows uses oaod, or CR&LF,

Linux/unix with OA, that is, LF.

MacOS used OD, or CR.

History: Before the advent of the computer, there was a device called a telex (teletype Model 33) that could be played 10 characters per second. But it has a problem, that is, after a line of line change, to use 0.2 seconds, just can hit two characters. If there are new characters coming in this 0.2 seconds, the character will be lost.

So the developers figured out a way to solve the problem by adding two characters to the end after each line. One is called "carriage return", which tells the typewriter to position the print head at the left edge, and the other is called "line-wrapping", telling the typewriter to move the paper down one line. This is the "line" and "return" of the history, from their English name can also be seen in one or two.

Later, the computer was invented, and the two concepts were also on the computer. At the time, memory was expensive, and some scientists thought it would be a waste to add two characters to the end of each line. So, there was disagreement. Unix system, the end of each line only "< newline >", that is, "\ n", Windows system, each line at the end of "< carriage return >< line >", that is, "\ r \ n", Mac system, each line at the end of "< Enter >." A direct consequence is that all text becomes a row when the files under the UNIX/MAC system are open in Windows, and Windows files open under Unix/mac, and a ^m symbol may be shown at the end of each line.

(When using FTP software to transfer files between different platforms, in ASCII text mode, some FTP clients automatically convert to a line format.) The number of bytes of file that has been transferred may vary. If you do not want FTP to modify the original file, you can use bin mode (binary mode) to transfer text)

\ n and \ r usage in the C language:

#include <stdio.h>

int main ()

{

printf ("938517\r10086\n");

return 0;

}

Whether it's a Linux system or a Windows platform, input is

10086

Because \ r is already wrapped, 938517 is no longer displayed. \ n is not really a newline, it actually moves the paper (or screen) down one (to display the next line of content).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.