Handling of ^ M line breaks in linux

Source: Internet
Author: User

 

Files edited in WINDOWS are often transferred to LINUX with a ^ M symbol at the end of each line, which leads to shell script running errors.

This is because the DOS editor and the Linux editor are inconsistent with the carriage return at the end of the file line.

 

There are two ways to remove ^ M

 

 

1. We can delete ^ M in the VI Editor:

Switch VI to the command line mode, and enter (note that this ^ M is input, instead of shift + ^ plus M, it should be ctrl + v plus ctrl + m)

: % S/^ M/g -- the command copy is invalid. Note that ^ M Input

Run the preceding command in vi command line mode to remove the ^ M at the end of all lines.

 

 

 

2. You can use the dos2unix command.

 

Dos2unix filename

 

This article is from the "richard's note" blog

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.