Line breaks in different operating systems

Source: Internet
Author: User
Tags ultraedit

We usually deploy the application on Linux, but when using VI to query application logs, we may find that there is^ MSymbol, as shown below

[20121121 07:53:19] [Pool-3-thread-3] [abstractaction] ^ m blocks ^ m [communication parties] (0x00004afe: NiO socket, server,/192.168.13.3: 59565 =>/192.168.12.2: 80) ^ m [transceiver id] receive ^ m [message content] Post/TRA/trade/nocardnopassword.htm HTTP/1.1 ^ mcontent-type: application/X-WWW-form-urlencoded; charset = gb18030 ^ mcache-control: No-Cache ^ mpragma: No-Cache ^ Muser-AGENT: Java/1.6.0 _ 24 ^ mhost: 192.168.20.1 ^ maccept: text/html, image/GIF, image/JPEG, *; q =. 2, */*; q =. 2 ^ mconnection: keep-alive ^ mcontent-length: 541 ^ m ^ mcoobankno = cmbc_credit & signtype = MD5 & amount = 499900 & ordervaliditynum = 15 & cvvno = 255 ^ m Weight [20121121 16:37:15] [Pool-3-thread-26] [abstractaction] ^ m ----------------- ^ M [communication parties] (0x0000e522: NiO socket, server,/58.83.141.39: 60796 =>/192.168.12.2: 80) ^ m [transceiver id] receive ^ m [message content] GET/policy_yeepay? P1_merid = 11 & r0_cmd = buy & r1_code = 1 & r2_trxid = 22 HTTP/1.1 ^ mcontent-type: Application/X-WWW-form-urlencoded; charset = GBK ^ mcache-control: No-Cache ^ mpragma: No-Cache ^ Muser-AGENT: Java/1.5.0 _ 14 ^ mhost: 123. 125. **. 248 ^ maccept: text/html, image/GIF, image/JPEG, *; q =. 2, */*; q =. 2 ^ mconnection: keep-alive ^ m success ------------------------------------------------------------------------------------------

Here we will extend a concept:Line breaks, that is, Cr (carriage return) and LF (line feed)Problems
NormallyEditplus-- Tool -- parameter settings -- text -- new file -->, three formats of PC, UNIX, and Mac are displayed.
InUltraedit-- Advanced -- configuration -- file processing -- new file type -->, three formats of DOS, UNIX, and Mac are displayed.
AndUltraeditYou can also specify the file format when saving the file: DOS: CRLF, Unix: Lf, Mac: Cr
In fact, Cr (carriage return) and LF (line feed) are used to represent the next line, but the methods used by different systems are different.
DOS/Windows SystemCRLF (Press ENTER + line feed)Indicates the next row.
Linux/Unix systemsLfIndicates the next row.
MAC systemCrIndicates the next row.
Note: The ascii value of Cr is 13 in decimal format, 0x0d in hexadecimal format, and LF is 10 and 0x0a.

In most computer languages, Cr is represented as a character or string"\ R", Lf is"\ N"
In the printf () function of each language"\ N"It indicates a logical meaning, that is, the next row in the current operating system.
Therefore, on UNIX, it indicates lf, and on Windows, it indicates CRLF.

In addition, the rfc2616 specification of HTTP/1.1 clearly states:
HTTP/1.1 defines the sequence of CRLF as the end of any protocol element, except for the entity (endtity-Body)
The line tail mark of an entity-body is defined by its corresponding media type.
Therefore, it can be roughly understood as the "[packet content]" part of the HTTP message posted above (that is, the original packet of the HTTP request)
Each line ends with a CRLF (so when using mina2.x to write an HTTP server, you can determine it based on 0x0d and 0x0a)


Finally, return to the topic:^ MSymbol
When usingVIWhen querying logs,VIInternally, this log is considered to be in Linux format, and it only recognizes lf
So VI will kill the CR and replace it with a ^ m symbol.


Next, we will introduce a history of Cr (carriage return) and LF (line feed ).
Before the computer appeared, it printed characters using teletype model 33, which can contain 10 characters per second
However, after hitting a row, it is found that it takes 0.2 seconds to wrap the line, and the 0.2 seconds can print exactly two characters.
If a new character is passed in the 0.2 s, the character will be lost because it is being wrapped in a line break.
To solve this problem, the developers decided to add two ending characters, namely Cr (Press ENTER) and LF (line feed), to the end of each line)
Cr (Press ENTER): tells the typewriter to relocate the print header to the left boundary of the row
LF (line feed): tells the typewriter to move the print head down one line, that is, move the paper down one line
Then, with the invention of the computer, this processing mechanism was moved to the computer.
However, memory was very expensive at the time. Some people thought it would be a waste to add two characters at the end of each line. Just add one character.
DOS/Windows systems use CRLF (I .e. press ENTER + line feed) to represent the next line
Linux/Unix systems use LF to represent the next line
The MAC system uses Cr to represent the next line.
The direct consequence of these differences is:
When a file in Linux/Unix is opened in windows, all the text will become a line (because Windows only considers CRLF to indicate line feed)
When opening files in Windows in Linux/Unix, a ^ m symbol may be added at the end of each line.
The ^ m symbol is a special mark specified by Linux and other systems. It occupies the size of a character. It is not a combination of ^ and M and cannot be printed.
And the ^ m symbol is only used for display. It is not actually written to the file.

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.