Convert the text dos format in linux to unix format and remove the ^ M symbol.

Source: Internet
Author: User


In linux, the text dos format is converted to the unix format, removing the ^ M symbol. Today, we are working on batch query statistics. Because the raw data is text copied from execl, use shell to analyze this batch of data. After waiting for a long time to get the result, I found that the data after the query export is empty, which is very depressing (there are still many things to do ). First, the shell script returns the SQL statements of all execution records to a single text, and finds that each query record exported is divided into two rows, at the beginning, I was not aware of the danger of ^ M. I tried to adjust the shell script repeatedly, So that I changed the shell script to the heaviest full-record search without any conditions. Www.2cto.com (there may be too many things to do, and the brain was not calm enough to grasp the main cause of the problem). The problem still failed to be solved and crashed. Finally, I took out a record and analyzed it separately. I carefully checked that the SQL records returned by the echo were ^ M, speechless.
(How can I ignore ^ M? I should despise myself. Isn't it always a loss ). Finally, compress sed-I "s/^ M/g" to replace it and re-start it. I lament that my recent status is indeed not good. I always feel very annoyed and need to adjust it. I found another article on the Internet that converts line breaks between UNIX and WINDOWS. I learned to add the following: syntax
Dos2unix [-kn] file [newfile] is converted from DOS to UNIXunix2dos [-kn] file [newfile] from UNIX to DOS, that is, WINDOWS-k: retain the original mtime of the document (the time when the last content of the document is not updated)-n: Retain the original document and enter the converted content into the new document. For example: dos2unix-n old new example: www.2cto.com $ cat-v killws #! /Bin/bash ^ Madmin_dir = "/home/admin" ^ Mfunction check_user {^ M if [['whoam '! = "Admin"]; then ^ M echo "Apache only can start by admin user, exit! "^ M exit ^ M fi ^ M} ^ M $ dos2unix-k killwsdos2unix: converting file killws to UNIX format... $ cat-v killws #! /Bin/bashadmin_dir = "/home/admin" function check_user {if [['whoam '! = "Admin"]; then echo "Apache only can start by admin user, exit! "Exit fi} www.2cto.com also has a conversion method: input set ff = unix in vim file directly. Save and quit! ------ End ------
 

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.