Skip to content
Home » Shell Script » How vi Editor Remove Control M

How vi Editor Remove Control M

Editing on client side computer has many advantages than on server side. In real world, Windows takes the largest market share on client environment, therefore, users could edit files with DOS format on client machines, then transport files to server for operation. But, when you display files on console, you might see the odd character ^M trailed every line:

[oracle@test sql_scripts]$ vi MoveAllTables.sql
...
SELECT OBJECT_NAME FROM DBA_OBJECTS WHERE OBJECT_TYPE='TABLE';^M
ALTER TABLE TABLE_NAME MOVE;^M
...
EXIT;^M

Although you can remove ^M one by one, there's a smart way to do it. In vi command mode, enter the following:

:%s/(Ctrl+v)(Ctrl+m)//g

The (Ctrl+v)(Ctrl+m) means you must hold Ctrl key then stroke v m keys subsequently.

Leave a Reply

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