Linux replace ^ M characters

Linux replace ^ M characters

 Under Linux use vim to view some text files created in Windows, the end of the line sometimes found some "^ M".

1. dos2unix command. General distribution release comes with the gadget (if not you can go to download based on the link below), easy to use:

$ dos2unix myfile.txt

The above command will remove the end of the line ^ M.

2. Use vi replacement function. Start vi, enter the command mode, enter the following command

:% S / G ^ M $ //                  # remove trailing M ^ 
:% S / G ^ M //                  # remove all M ^ 
:% S / M ^ / [Ctrl-V] + [Enter] / G   # ^ M replace the ENTER 
:% S / ^ M / \ R & lt / G                 # replaced into the transport ^ M

 3. Use the sed command. And the use vi similar to:

$ sed -e ‘s/^M/\n/g’ myfile.txt

 Note: This "^ M" to use "CTRL-V CTRL-M" is generated, rather than directly typing "^ M".

 

 

Guess you like

Origin www.cnblogs.com/fieldtianye/p/11244486.html