The \ r character in the shell script.

Source: Internet
Author: User

On Windows with notepadd++ edit a shell script, die or die, back to Linux, edit, or have this \ r, search the next, is this:

http://bluemood.blog.51cto.com/1142811/1030925


because the shell processed the character file in Windows, the string that was supposed to output two lines became a line, and some characters from the beginning of the first line were overwritten by the second line.

This is due to the difference between the/R ^m characters under Windows and Linux, which can filter out the exception characters and then output: as sed ' s/[^0-9,.:a-za-z]//g ' filters out characters that do not conform to the rules

Reproduced below can be referenced below:

In the UNIX system, the end of each line is only "< line >", or "\ n", and in the Windows system, each line ends with "< newline >< Enter >", or "\n\r". As a direct result, when files in the UNIX system are opened in Windows, all the text becomes a line, and the files in Windows are opened under UNIX, which may have a ^m symbol at the end of each line.


Okay, so my problem is that there are ^m symbols at the end of each line of the file that is being processed, and that's usually not visible. Can be viewed with the "cat-a test.file" command. When I want to add a character at the end of a line, it is always added at the beginning of the line and overwrites the character at the beginning of the line.

There are two ways to convert a file:

1. Command Dos2unix test.file

2. Remove the "\ r" and use the command sed-i "s/\r//" "Test.file

OK, so deal with the punishment, OK ...

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.