Convert Windows format files to Linux format

Source: Internet
Author: User
How to convert Windows format files to Linux format-general Linux technology-Linux technology and application information. The following is a detailed description. When processing files in Linux, we sometimes see a pile of ^ M at the end of the line. This is a line break in the Windows style. The lines "Dizzy to death" are separated by 0d 0a, Which is annoying, but there is a historical reason.

Little story: Why do I need 0d 0a for another line?

Long ago, the printer was the oldest mechanical unit at that time. After hitting a line, it had to do two things: the first thing was to move the print head back from the end of the line to the line head, the printed head moved and removed is called a carriage in the image, and the car is returned to the left, naturally, we call it Carriage Return ). The second thing is to move the paper up one Line. This process is called Line Feed. Therefore, in the ASCII code table, 0d is CR and 0a is LF.

This is the history of 0d 0a in Windows. Linux may think this is stupid and outdated. A Line Feed can directly create a new Line. Therefore, in Linux, 0a is always used to represent the new Line.

After the story is over, let's go back to the question. What should I do after I find these files in Linux?

I. Qian Kun moved to another place: copy the file to Win and convert it to a LINUX file using UE, WINHEX, and so on. (The name is handsome, but the trick is too earthy !).

Ii. Two-way pull: open with vim. In Normal mode, Enter % s/[Ctrl-v] [Enter] // g, ctrl-v indicates that the Enter key is considered a special character, rather than the end of the command.

3. Make sure that the downloaded source files are the same. You cannot use vi to open them one by one, so you can use dos2unix, for example: you need to change all the source files in the current directory to the unix format: dos2unix *. h *. cpp

Note: In fact, ^ M is 0a strictly speaking. Here we will not discuss the technical details of the mask.
Related Article

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.