Removing the trailing ^M characters in vi

:%s/^V^M//g 

where: ^V^M means CTRL-V followed by CTRL-M 

From here