Turn: In the Linux VI file in the end of the strange ^m and solve

Source: Internet
Author: User

^m in the Linux editor vim to delete the end of a line

Sometimes, when you open a file in Linux that you've edited in Windows, you see ^m characters at the end of the line. It always feels awkward.

The deletion method is as follows:

In the Vim command mode, enter:%s/^m$//g, enter will automatically delete all the ^m characters in the file.

Note: ^m to enter with CTRL + V, CTRL + M, tapping ^ and m directly on the keyboard is no good! The following $ represents the content that matches the end of the line, and the last G indicates that the match in each line is replaced--the global substitution, otherwise only the first match to each row is replaced.

and the script removal method:

Cat File | Col-b > FILE.1//This can be removed, but the characters in the generated file are garbled

Sed-e ' s/.$//g ' File//correct

Sed ' s/^m//' file//correct, but ^m = Ctrl + V, CTRL + M

Appendix: ^m Another scenario is where files are routed through FTP between Windows and Linux systems. This is the recommended method is: Forcibly set the FTP mode for the ASCII way can ah! Of course, it can be done by software Dos2unix. I haven't tried, huh?

Turn: In the Linux VI file in the end of the strange ^m and solve

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.