^M magically appears on scripts when we copy a file from windows to Linux OS after modification.
To
remove the ^M characters at the end of all lines in VI use below command:
:%s/^V^M//g
The
^V is a CONTROL-V character and ^M is a CONTROL-M. When you type this, it will
look like below command. In
UNIX, you can escape a control character by proceeding it with a CONTROL-V.
:%s/^M//g
The
:%s is a basic search and replace command in VI. Above command tells VI to replace all the ^M character globally with nothing and to escape ^M we need to type ^V.
Enjoy
Manisha
No comments:
Post a Comment