How to remove ^M characters at the end of lines in Vi from files in Linux?

Files created in windows when moved to linux will have ^M character at the end of lines when you open the files in Vi editor.

To remove the strange characters open the file in Vi editor and type

:%s/.$// 


This will search for the ^M pattern on the entire file and will remove all occurences.

Other option is to open the file with the strange characters and use the following search and replace pattern

:%s/^V^M//g

In the above command you need to press ctrl+v and ctrl+m in order for you to get the character ^M in the vi editor

Share

Written by kurinchilamp


Website: http://

Leave a Reply

Your email address will not be published. Required fields are marked *

Kurinchi Calendar
January 2013
M T W T F S S
« Dec   Feb »
 123456
78910111213
14151617181920
21222324252627
28293031