Linux Replacement ^m Character method

Source: Internet
Author: User

Transferred from: http://blog.csdn.net/lhf_tiger/article/details/8203013

It's disgusting, the 10X process generated by the CSV file row bit actually has ^m characters, harm I have been looking for the cause of the error, really pit, fortunately, I finally found out. have been using Python,perl is becoming more and more unskilled. Commissioning took a long time.

Replace ^m characters
Use VI under Linux to see some text files created under Windows, and sometimes find some "^m" at the end of the 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 following connection), it is convenient to use:
$ Dos2unix MyFile.txt
The above command will remove the ^m at the end of the line.

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

:%s/^m//g # Remove all the ^m.

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

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

3. Use the SED command. Similar to the use of VI:
$ Sed-e ' s/^m/\n/g ' myfile.txt

Note: "^m" Here is generated using "Ctrl-v ctrl-m" instead of typing "^m" directly.

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

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

Linux Replacement ^m Character method

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.