Linux-simulate the dos2unix command

Source: Internet
Author: User

Linux-although I am not an O & M engineer for simulating dos2unix commands, I have encountered some interesting problems due to studying linux and shell scripts, for example, we often upload text files in the window environment to linux. Due to the different terminologies of the two, sometimes the configuration problem occurs because linux does not know the terminator of the original window environment, in this way, we can re-Add the terminator under the original Terminator. We can use cat-v-E test.txt to view the data.-v indicates that the hidden character-E indicates that the Terminator is displayed, the data is as follows: www.2cto.com 395439881 ^ M $ ^ M is the ending character of the window file, which is displayed in linux, $ is the ending character 395423434 ^ M $395468635 ^ M $395436444 ^ M $395463623 ^ M $. Well, we will replace the ending character in the window, otherwise it will not work properly, we can use the following methods to process www.2cto.com cat test.txt | Tr-d '\ R' | cat-v. Let's use cat-v to check whether the character is successfully replaced. 395439881395423434395468635395436444395463623. What if the hidden character is not \ r? cat-v test.txt | sed's: \ (\ ^ \ w \ + \):: '| cat-v 395439881395423434395468635395436444395463623 note that cat-v may display hidden characters in special ways. Therefore, you can directly replace them when passing through pipelines, here, after cat-v, \ r cannot represent the window Terminator, which is converted ...... Mcat test.txt | sed's: \ r: '| cat-v is the easiest way to use the dos2unix command.

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.