[Arrangement] How to cancel the ^ m symbol displayed in VI in Linux

Source: Internet
Author: User

From: http://apps.hi.baidu.com/share/detail/30042616

[Arrangement] How to cancel the ^ m symbol displayed in VI in Linux

Background Knowledge]

^ M is '\ R' in ASCII, carriage return, 0x0d in hexadecimal notation, 015 in hexadecimal notation, and 13 in decimal notation.

For the line feed action, there is generally only one 0x0a in UNIX to indicate line feed. in windows, there are generally two characters: 0x0d and 0x0a.

In addition, ^ L is an ASCII 0x0c '\ F', a form feed control character.

For Linux VI, some versions, such as the VI in my current development board, are compiled using busybox and cannot recognize the text files edited under Windows with 0x0d. Therefore, you can edit a common text file in windows. If there is a line break, the corresponding 0x0d will be displayed in the Linux VI.^ MFor example:

1. Led on & off ^ m
Eg. ^ m
Echo none>/sys/class/LEDs/led_green/trigger ^ m
Echo 1>/sys/class/LEDs/led_green/brightness ^ m
Echo>/sys/class/LEDs/led_green/brightness ^ m
Note: The default switch of trigger is [none] ^ m
2. Heartbeat flash ^ m
Eg. ^ m
Echo heartbeat>/sys/class/LEDs/led_green/trigger ^ m
3. Timer flash ^ m
Eg. ^ m
Echo timer>/sys/class/LEDs/led_green/trigger ^ m
Echo 5>/sys/class/LEDs/led_green/delay_on ^ m
Echo 5>/sys/class/LEDs/led_green/delay_off ^ m

Each row has a ^ m at the end, which is very ugly, so you want to remove it.

Note: Linux in a common PC version can be well identified. For example, on my Linux server, a version of VI under opensuse can display the edited versions under windows, enter a line break with 0x0d. ^ m is not allowed.

In addition, the following is a brief introduction to ASCII characters in Linux:

[Crifan @ linux-41lh Wi-Fi] $Man ASCII

ASCII (7) Linux programmer's Manual ASCII (7)

 

Name

ASCII-the ASCII character set encoded in octal, decimal, and hexadecimal

 

Description

ASCII is the American Standard Code for information interchange. it is a 7-bit code. listen 8-bit codes (such as ISO 8859-1, the Linux default Character Set) contain ASCII as their lower half. the international counterpart of ASCII is known as ISO 646.

 

The following table contains the 128 ASCII characters.

 

C program '\ x' escapes are noted.

 

Oct dec hex char

------------------------------------------------------------------------

000 0 00 NUL '\ 0' 100 64 40 @

001 1 01 Soh (start of heading) 101 65 41

002 2 02 STX (start of text) 102 66 42 B

003 3 03 etx (end of text) 103 67 43 C

004 4 04 EOT (end of transmission) 104 68 44 d

005 5 05 Enq (Enquiry) 105 69 45 E

006 6 06 ack (acknowledge) 106 70 46 F

007 7 07 Bel '\ A' (Bell) 107 71 47g

010 8 08 BS '\ B' (backspace) 110 72 48 h

011 9 09 HT '\ t' (horizontal tab) 111 73 49 I

012 10 0a lf '\ n' (New Line) 112 74 4A J

013 11 0b VT '\ V' (vertical tab) 113 75 4B K

014 12 0C FF '\ f' (Form feed) 114 76 4C L

015 13 0d Cr '\ R' (carriage RET) 115 77 4D m

016 14 0e so (shift out) 116 78 4E n

017 15 0f Si (shift in) 117 79 4f o

...........

 

[How to eliminate ^ m in VI]

I used the SED command at the beginning:

Sed's/^ m // G' file_old> file_new

Failed. Open the output file with VI or with ^ m.

Then I found the available methods on the Internet and used the tr command:

 

Tr-d "\ 015" <myfile.txt> myfile_new.txt

 

You can delete the ^ m ("\ 015") symbol and upload it to the new file myfile_new.txt.

[Postscript]

According to the suggestions of others, we know that there is also a dedicated tool dos2unix and unix2dos, which is used to handle this problem. For details, refer:

[Switch] Use dos2unix and unix2dos commands

Http://hi.baidu.com/serial_story/blog/item/ddc783314af738a55fdf0ee2.html

It is easy to use and can be used directly:

Dos2unix file_name

In this way, the 0x0d in the file is removed, and only 0x0a is retained.

[Reference]

1.How to cancel the ^ m symbol displayed in VI

Http://hi.baidu.com/nourewang/blog/item/7d2f9e84069d6e3466096e1a.html

2.In Linux, the file created by a program contains the ^ m character. How can this problem be eliminated ??

Http://www.linuxforum.net/forum/printthread.php? Cat = & board = Program & main = 32848 & type = thread

3.[Ask] What do ^ m and ^ l appear when editing text with Vi?

Http://www.linuxsir.org/bbs/thread305370.html

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.