Hi,
I have a file copied from Windows in which there are many ^M, how can I delete them in VI editor ?
Many thanks.
dos2unix <filename>
thank you, but how in VI editor ?
Regards.
when in vi:
:%s/^M$//
Note: you can get "^M" pressing CTRL+V and next CTRL+M
many thanks.
cat filename |col -b > newfile works as well
:%s/{CTRL+V}{CTRL+M}//{Enter}
should work too.
I find it easier to just keep a couple shell aliases around
alias unix2dos="perl -i -pe 's/\r//g'"
alias dos2unix="perl -i -pe 's/\n/\r\n/'"
Hope this helps!
That's the method I use.
Interesting to note that on the way back to dos, you can reverse the process without problem (:%s/$/^V^M/). It's all good. Another interesting insert you may find useful is ^L for form-breaks, but we used that before when "pr" was the normal way to feed the lpd. Now it seems all is a GUI world and WYSIWYG. Much to my own shame I have forgotten most everything I knew about troff/nroff and stick to my Mac editor and even Word when forced by circumstances.
S.
and if your vi is really vim then
:set fileformat=unix
will do the trick
:set fileformat=dos
will pop it back