Replace ^ m with vim

Source: Internet
Author: User

Cause: Press enter to indicate:In dos, press enter (Cr, ASCII 13, r) to wrap (LF, ASCII 10, n. There is only one in Linux.

In Linux, you can use VI to view some text files created in windows. Sometimes you will find some "^ m" at the end of the line ". There are several methods for processing.

1. Use the dos2unix command. This tool is included in the general distribution version (if not, you can download it based on the following connection), which is very convenient to use:
$ Dos2unix myfile.txt
The above command removes the ^ m at the end of the line.

2. Use the replacement function of VI. Start VI and enter command mode. Enter the following command:
: % S/^ m $ // G # Remove the ^ m at the end of the row.

: % S/^ m // G # Remove all ^ m.

: % S/^ m/[Ctrl-v] + [enter]/G # Replace ^ m with the carriage return.

: % S/^ m/R/G # Replace ^ m with the carriage return.

3. Use the SED command. Similar to VI:
$ Sed-E's/^ m/n/G' myfile.txt

Note: Here '^ m' is generated using the CTRL-V CTRL-M instead of directly typing '^ m ".

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.