Replace ^M in lines

PDF
Sometimes when editing a file which was created on a machine other then your Linux machine, each line ends up with a visible ^M (CTRL + M). To remove this at each line you can use vi. In vi you can escape a control character by preceding it with a ^V (CTRL + V). Now using the search and replace command you can easily change the ^M (CTRL + M) in all lines. Change vi to the escape mode and type
%s/^V^M//g
CTRL+V and CTRL+M, this will look on your screen as:
%s/^M//g
Tags:
 

Please login first before adding a comment.

Search






You are here: Home Howtos and FAQs Bash Replace ^M in lines