If I open files I created in Windows, the lines all end with ^M
.
How do I delete these characters all at once?
相关问题
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- how to get running process information in java?
- Spring Integration - Inbound file endpoint. How to
- Error building gcc 4.8.3 from source: libstdc++.so
In Vim, that strips all carriage returns, and leaves only newlines.
The comment about getting the ^M to appear is what worked for me. Merely typing "^M" in my vi got nothing (not found). The CTRL+V CTRL+M sequence did it perfectly though.
My working substitution command was
and it looked like this on my screen:
Change the lineendings in the view:
This can also be used as saving operation (:w alone will not save using the lineendings you see on screen):
And you can use it from the command-line:
Usually there is a
dos2unix
command you can use for this, just make sure you read the manual as the GNU and BSD versions differ on how they deal with the arguments.BSD version:
GNU version:
Alternatively, you can create your own
dos2unix
with any of the proposed answers here, for example:To run directly into linux console:
vim file.txt +"set ff=unix" +wq
dos2unix
can directly modify the file contents.You can directly use it on the file, with no need for temporary file redirection.
The above uses the assumed US keyboard. Use the
-
437 option to use the UK keyboard.