How to remove the "^M" in some dos file
When I edit some dos file int Vim, it has a "^M" at the end of each line.
How to remove them from my file? |
You need a utility named something like "dos2unix" Different distros give it different names, but it reformats files createdin DOS, to a unix format.
|
I think you can run fromdos on it and remove them.
|
If you can't find dos2unix (I haven't got it on Slackware), you can use
Code:
perl -i -wpe 's/\r$//' <files> |
^M is the carriage return character.
Windows text files use a combination of carriage return plus line-feed characters as the end-of-line marker; Unix, Linux, and most other platforms use just the line-feed character. Files created on Windows will therefore have additional ^M characters at the end of every line when viewed in Linux. Likewise, files created in Linux and viewed in Windows will lose all their line-breaks. Solutions: 1) As has been stated, there are utilities to convert files between the two formats. 2) If you're using FTP to transfer the files, switch it to ASCII mode when you upload or download the files, and the FTP server will convert the line feeds automatically for you. 3) Open the file in an editor that can recognise either format -- in Windows, use Wordpad instead of Notepad. In Linux, I find that KDE's KWrite does the job very nicely, but I'm sure there are others that work just as well. Hope that helps :) |
Code:
tr -d '\r' < inputfile > outputfile ppanyam |
Quote:
Good method, thank you. And I defined Code:
map <C-d><C-u> :%s/&\r$//g^M When I edit a dos file with vim, I can type Ctrl+d,Ctrl+u remove them. |
Hi,
Another possibility (in vim): set ff=unix / set ff=dos |
you can install recode (if not already installed) and run
recode dos 'yourfile' |
Quote:
|
All times are GMT -5. The time now is 04:52 PM. |