When I am editing source files using vim and other editors sometimes at the end of the line I get these ^M characters at the end of each line. I think that it has something to do with editing a file in windows and then in linux. How can I remove all of these automatically?
相关问题
- Is shmid returned by shmget() unique across proces
- Inheritance impossible in Windows Runtime Componen
- how to get running process information in java?
- Is TWebBrowser dependant on IE version?
- How can I have a python script safely exit itself?
This worked for me in a file that had everything on one line:
First find all matches
(To get
^M
, press ^V ^M, where ^ is Ctrl on most keyboards)Then replace with newlines
Combined command would be:
One easy way to strip out the DOS line endings is to use the
ff
option:Now your file is back to the good-old-Unix-way.
If you want to add the DOS line-endings (to keep a printer happy, or transfer files with Windows friends who don't have nice tools) you can go the opposite direction easily:
The origin of the problem may have been through an FTP transfer. When you FTP these files from one box to another, make sure to use ASCII transfers. Use the command "ASC."
There's a program called dos2unix that should strip those for you. Windows uses different line-ending characters which is why that happens.
You can do this:
It will hide the
^M
's, without touching the file.