This is pretty standard search an replace command in vi, but I always forget how to specify the carriage return character (‘^M‘): Ctrl+V for the ‘^‘ and Ctrl+M for the ‘M

The command is:

:%s/^M//g

For those new to vi:

While you have the file opened in vi, hit Escape to make sure you are in command mode. Then type ā€œ:ā€ to go to the command line and then type the string shown above. The ^M portion of this command requires typing Ctrl+V to get the ^ and then Ctrl+M to insert the M. The %s is a substitute operation, the slashes again separate the characters we want to remove and the text (nothing) we want to replace it with. The ā€œgā€ (global) means to do this on every line in the file.

Remove Windows carriage return characters with vi

Leave a Reply

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

*