How to remove ^M characters from a file

Sometimes you come across a file, maybe a config file for some application you have installed, that has a load of ^M chars at the end of each line.. perhaps because the file at one time lived on a windows pc. But now it’s on your linux server and you need to remove all that garbage, here’s a simple way to do it..

Open the file with vi or vim and type this..

:%s/^V^M//g

that ^V^M is actually just ctrl+VM

Thats it, save the file and exit. ( :wq)

 

 

You may also like...