[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to delete ^M

From: address@hidden
Subject: Re: How to delete ^M
Date: Mon, 12 May 2003 02:16:32 -0400
User-agent: KNode/0.7.1

Wang, Zhu wrote:

> Hello,
> I am frustrated by a probably very simple problem:
> Each line of a file ended by ^M. I think this is caused by 'ENTER'. How
> can I delete them simultaneously?
> Thanks for your help.
> Zhu Wang
> Southern Methodist University

It was likely a DOS/Windows file. That ^M is Emacs' way to show a carriage 

There's a slight difference between symbols used to mark the line ends in 
Linux/unix and DOS/Windows files. Linux/unix uses just a plain newline, 
which if shown, would be ^J, but usually isn't shown. DOS/Windows uses a 
carriage return and THEN a newline. Mac, naturally, uses just a carriage 

The easiest way would be to just copy the ^M and then paste it into M-x 
replace-regexp in the "search" portion. Then put nothing in the "replace" 
portion. That'll make it go through the file and remove all the carriage 

You can also use C-q 015 in the "search" portion for the carriage return. 
That'll give the ASCII equivalent. C-q 012 will find the ^J, if you ever 
need to do that. C-q 011, incidentally, is for tabs.

Since I have a lot of old DOS/Windows text files around, I made macros to 
convert the line ends--both ways. I bound them to function keys.

If you have a lot of these files, and you're on Linux/unix, there are the 
Todos and Fromdos programs, which will convert the line ends on whole 
bunches of files. See the man pages.

Some programs are sensitive to the line endings. In Windows Notepad, for 
example, a Linux/unix text file will melt into one huge paragraph. But most 
programs don't care. They'll adjust and display it correctly.

If you're programming something, though, it could make a huge difference.


Author of "Linux for Non-Geeks--Clear-eyed Answers for Practical Consumers" 
and "Boring Stories from Uncle Rod." Both are available at

To reply by e-mail, take the extra "o" out of my e-mail address. It's to 
confuse spambots, of course.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]