Difference between line breaks in Linux and Windows
The line breaks for Linux are not wrapped in Windows Notepad or appear as a result of line break differences in Linux and Windows.
First look at the return sign and the line break symbol to produce the background
The origins and differences between the two concepts of "enter" (carriage return) and "line feed".
Before the computer appeared, there was a device called the teletype Model 33, which could play 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 in
In this 0.2 seconds, a new character is passed, and 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.
In a UNIX system, only "< newline >", or "n", is at the end of each line. Inside the Windows system, the end of each line is "< return >< change line >", that is, "RN"; In the Mac system, the end of each line is "< return >". A direct consequence is that the files under the UNIX/MAC system
When Windows opens, all text becomes one line, and Windows files are opened under Unix/mac, and a ^m symbol may be shown at the end of each line.
The files created by Windows are NR-terminated, and the Unix-class system LINUX,MAC is N-terminated.
So the UNIX text to Windows will appear line-break loss (UltraEdit This software can be correctly identified); In turn, there will be ^m symbols;
The text line breaks used by Windows and other operating systems are different from the Unix/linux operating system, and the line breaks entered under the Windows system are not displayed as "Unix/linux", but rather as symbols for ^m (this is a special tag specified under Linux and other systems).
The size of one character, not the combination of ^ and m, does not print out. Many of the text editors (command lines) under Linux will display this tag, make up one of your own line breaks to avoid clutter (just to show that the supplemental newline character is not written to the file, with a special command to replace the Windows newline character with a Linux newline character). Line breaks under the Unix/linux system are ignored in the Windows System Text Editor, and the entire text is mess.
Windows wrapping is RN and the hexadecimal value is: 0d0a.
The Linux newline is n and the hexadecimal value is: 0A
So in the Linux saved files on Windows with Notepad to look at the black dots, we can use Linux under the command of the file format to convert to the win format.
Unix2dos is to convert Linux file format to Windows file format
Dos2unix is to convert Windows format to linux file format.
Linux Remove Windows line break ^m
OJ found a problem: The code read in%c will be reported to WA. Later found to be related to scanf. Use%c to read N and r two characters under Linux. So you need to delete the ^m (aka R) character.
There are many ways to delete it. Found a relatively simple.
To remove the ^m from the A.txt and write to the B.txt, use the following instructions: Cat A.txt | tr-d "^m" > B.txt
Note: The ^m in the statement is entered through CTRL + V, ctrl+m. specifically/R character
Unix line breaks only: R
Dos line breaks are: RN
Specifically, R's ASCII code is: 14
The ASCII code for n is: 10