Linux Replacement ^m Character Method __linux

Source: Internet
Author: User

Replace ^m character
Use VI to view some of the text files created under Windows under Linux, sometimes finding "^m" at the end of a line. There are several ways to handle this.

1. Use the Dos2unix command. This gadget is available in the general distribution version (if it is not available to download according to the connection below), it is easy to use:
$ Dos2unix MyFile.txt
The above command will remove the ^m at the end of the line.

2. Use VI to replace the function. Start VI, enter command mode, and enter the following command:
:%s/^m$//g # Remove the ^m from the end of the line.

:%s/^m//g # get rid of all ^m.

:%s/^m/[ctrl-v]+[enter]/g # Replaces ^m with a carriage return.

:%s/^m/\r/g # Replaces ^m with a carriage return.

3. Use sed command. Similar to VI usage:
$ Sed-e ' s/^m/\n/g ' myfile.txt

Note: the "^m" here will be generated using "Ctrl-v ctrl-m" instead of typing "^m" directly.

Turn from: http://hi.baidu.com/mofeis/blog/item/23c7b2fb92dc97234e4aea6d.html


In Vim's _VIMRC file, remove Fileformat=unix.

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.