How does Linux get rid of ^m

Source: Internet
Author: User

  1. Under Linux, it is unavoidable to use vim to open some edited text files under Windows. We will find a ^m symbol at the end of each line of the file, because the DOS editor and the Linux editor are inconsistent with the carriage return at the end of the file line.
  2. For a carriage return definition:
  3. windows:0d0a
  4. unix\linux:0a
  5. mac:0d
  6. There are several ways to remove these symbols more quickly:
  7. (1) is the command with VI:
  8. Open a text file with VI
  9. VI Dos.txt
  10. Command mode input
  11. : Set Fileformat=unix
  12. : W
  13. (2) VI using regular expressions to replace
  14. g/\^m/s/\^m//
  15. Or
  16. %s/^m//g
  17. (3) using the SED tool
  18. Sed ' s/^m//' filename > Tmp_filename
  19. (4) Since the window of the carriage return more than ' \ R ', then of course, by deleting ' \ R ', can also be achieved:
  20. Tr-d ' \ r '
  21. (5) The last method is my most commonly used method, personally feel most convenient
  22. Under the Terminal Knock Command:
  23. $ Dos2unix filename
  24. switch directly to UNIX format and it's OK! ~

How does Linux get rid of ^m

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.