* Removing control M
@ 2014-02-28 20:16 peaches20
2014-02-28 20:40 ` Jai Dayal
` (3 more replies)
0 siblings, 4 replies; 13+ messages in thread
From: peaches20 @ 2014-02-28 20:16 UTC (permalink / raw)
To: Help-gnu-emacs
Hi,
I've transferred several dos files to unix. I now have the control M at tne
end of the line. How does one remove this globally. I tried the dos2unis
but that is not in my emacs commands.
Thanks.
Peaches
--
View this message in context: http://emacs.1067599.n5.nabble.com/Removing-control-M-tp315636.html
Sent from the Emacs - Help mailing list archive at Nabble.com.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Removing control M
2014-02-28 20:16 Removing control M peaches20
@ 2014-02-28 20:40 ` Jai Dayal
2014-02-28 20:43 ` peaches20
2014-02-28 21:01 ` Bob Proulx
` (2 subsequent siblings)
3 siblings, 1 reply; 13+ messages in thread
From: Jai Dayal @ 2014-02-28 20:40 UTC (permalink / raw)
To: peaches20; +Cc: help-gnu-emacs
dos2unix is not an emacs command, but a shell command.
On Fri, Feb 28, 2014 at 3:16 PM, peaches20 <watson1724@comcast.net> wrote:
> Hi,
>
> I've transferred several dos files to unix. I now have the control M at
> tne
> end of the line. How does one remove this globally. I tried the dos2unis
> but that is not in my emacs commands.
>
> Thanks.
>
> Peaches
>
>
>
> --
> View this message in context:
> http://emacs.1067599.n5.nabble.com/Removing-control-M-tp315636.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
>
>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Removing control M
2014-02-28 20:16 Removing control M peaches20
2014-02-28 20:40 ` Jai Dayal
@ 2014-02-28 21:01 ` Bob Proulx
[not found] ` <mailman.16317.1393620062.10748.help-gnu-emacs@gnu.org>
2014-03-12 14:26 ` Ken Goldman
3 siblings, 0 replies; 13+ messages in thread
From: Bob Proulx @ 2014-02-28 21:01 UTC (permalink / raw)
To: peaches20; +Cc: Help-gnu-emacs
peaches20 wrote:
> I've transferred several dos files to unix. I now have the control M at tne
> end of the line. How does one remove this globally. I tried the dos2unis
> but that is not in my emacs commands.
There are several different strategies for dealing with changing line
ending conventions. One is "dos2unix". That is a command line
program unrelated to emacs. You use it on the command line to filter
the file from one to the other. If you don't have dos2unix installed
then you can simply use 'tr' to do so.
tr -d '\015\032' < input.txt >output.txt
Inside emacs for an internal emacs solution there are several
strategies. One is to visit the file without any content conversion
at all. Then the ^M and ^Z characters show up as literal characters
and may be deleted. This is brute force but simple to understand and
I still do it the most often when I need this.
M-x find-file-literally
Visit a file with no conversion of the contents.
M-x replace-string <RET> STRING <RET> NEWSTRING <RET>
Using ^q^m as the string to replace
But perhaps the most elegant way is to use the emacs coding system to
do this. You can specify the coding system to use and specify unix
file coding when you save the file.
C-x <RET> c unix <RET>
C-x C-s
Modify the file first to make sure it is modified so that it will be
saved. You can mark a buffer as modified explicitly using the
not-modified key M-~ with an argument. The full sequence looks like
this sequence.
C-u M-~
C-x <RET> c unix <RET>
C-x C-s
The above is probably the most emacs way of doing this inside emacs.
But there isn't anything wrong with using 'tr' or 'dos2unix' or
whatever on the file outside of emacs. Whatever.
If you need to convert character encodings then that is an additional
need. Please say so explicitly. The "iconv" program is a tool that
can be used to convert almost any encoding to another one.
iconv -f CP1252 -t UTF-8 < infile.txt > outfile.txt
Bob
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.16317.1393620062.10748.help-gnu-emacs@gnu.org>]
* Re: Removing control M
[not found] ` <mailman.16317.1393620062.10748.help-gnu-emacs@gnu.org>
@ 2014-02-28 21:25 ` Dan Espen
2014-02-28 21:44 ` Mike Ray
` (2 more replies)
0 siblings, 3 replies; 13+ messages in thread
From: Dan Espen @ 2014-02-28 21:25 UTC (permalink / raw)
To: help-gnu-emacs
>>>>> "Jai" == Jai Dayal <dayalsoap@gmail.com> writes:
Jai> dos2unix is not an emacs command, but a shell command.
Jai> On Fri, Feb 28, 2014 at 3:16 PM, peaches20 <watson1724@comcast.net> wrote:
>> Hi,
>>
>> I've transferred several dos files to unix. I now have the
>> control M at tne end of the line. How does one remove this
>> globally. I tried the dos2unis but that is not in my emacs
>> commands.
To remove the control M's, just use Emacs normal find replace.
To type a ^M. type ^Q first.
A normally operating ftp program would have converted line endings
automatically assuming you used ascii mode (not binary).
--
Dan Espen
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Removing control M
2014-02-28 21:25 ` Dan Espen
@ 2014-02-28 21:44 ` Mike Ray
2014-03-01 7:55 ` Eli Zaretskii
[not found] ` <mailman.16341.1393660562.10748.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 13+ messages in thread
From: Mike Ray @ 2014-02-28 21:44 UTC (permalink / raw)
To: help-gnu-emacs
On 28/02/2014 21:25, Dan Espen wrote:
>>>>>> "Jai" == Jai Dayal <dayalsoap@gmail.com> writes:
> Jai> dos2unix is not an emacs command, but a shell command.
> Jai> On Fri, Feb 28, 2014 at 3:16 PM, peaches20 <watson1724@comcast.net> wrote:
>
> >> Hi,
> >>
> >> I've transferred several dos files to unix. I now have the
> >> control M at tne end of the line. How does one remove this
> >> globally. I tried the dos2unis but that is not in my emacs
> >> commands.
>
> To remove the control M's, just use Emacs normal find replace.
> To type a ^M. type ^Q first.
>
> A normally operating ftp program would have converted line endings
> automatically assuming you used ascii mode (not binary).
Or do thusly:
sed -i 's:\r::' input_file
--
Michael A. Ray
Analyst/Programmer
Witley, Surrey, South-east UK
The box said: 'install Windows XP, 7 or better'. So I installed Linux
Interested in accessibility on the Raspberry Pi?
Visit: http://www.raspberryvi.org/
From where you can join our mailing list for visually-impaired Pi hackers
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Removing control M
2014-02-28 21:25 ` Dan Espen
2014-02-28 21:44 ` Mike Ray
@ 2014-03-01 7:55 ` Eli Zaretskii
2014-03-01 8:31 ` Yuri Khan
[not found] ` <mailman.16341.1393660562.10748.help-gnu-emacs@gnu.org>
2 siblings, 1 reply; 13+ messages in thread
From: Eli Zaretskii @ 2014-03-01 7:55 UTC (permalink / raw)
To: help-gnu-emacs
> From: Dan Espen <despen@verizon.net>
> Date: Fri, 28 Feb 2014 16:25:41 -0500
>
> To remove the control M's, just use Emacs normal find replace.
> To type a ^M. type ^Q first.
When (in what Emacs version) did you last try that, and it worked?
If you visit a file normally, i.e. via "C-x C-f", you won't see any ^M
characters at all. You will see a "(DOS)" indication in the mode line
instead. This has been so since Emacs 20 at least.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Removing control M
2014-03-01 7:55 ` Eli Zaretskii
@ 2014-03-01 8:31 ` Yuri Khan
2014-03-01 9:00 ` Eli Zaretskii
0 siblings, 1 reply; 13+ messages in thread
From: Yuri Khan @ 2014-03-01 8:31 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: help-gnu-emacs@gnu.org
On Sat, Mar 1, 2014 at 2:55 PM, Eli Zaretskii <eliz@gnu.org> wrote:
> If you visit a file normally, i.e. via "C-x C-f", you won't see any ^M
> characters at all. You will see a "(DOS)" indication in the mode line
> instead. This has been so since Emacs 20 at least.
That’s if all lines end in the DOS way, with ^M^J. But if some lines
have DOS line ends and others have Unix line ends, then Emacs chooses
the Unix format and displays ^M on DOS-ended lines.
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Removing control M
2014-03-01 8:31 ` Yuri Khan
@ 2014-03-01 9:00 ` Eli Zaretskii
0 siblings, 0 replies; 13+ messages in thread
From: Eli Zaretskii @ 2014-03-01 9:00 UTC (permalink / raw)
To: help-gnu-emacs
> Date: Sat, 1 Mar 2014 15:31:41 +0700
> From: Yuri Khan <yuri.v.khan@gmail.com>
> Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
>
> On Sat, Mar 1, 2014 at 2:55 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
> > If you visit a file normally, i.e. via "C-x C-f", you won't see any ^M
> > characters at all. You will see a "(DOS)" indication in the mode line
> > instead. This has been so since Emacs 20 at least.
>
> That’s if all lines end in the DOS way, with ^M^J. But if some lines
> have DOS line ends and others have Unix line ends, then Emacs chooses
> the Unix format and displays ^M on DOS-ended lines.
Indeed. However, the OP's situation seems to be the former, not the
latter.
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.16341.1393660562.10748.help-gnu-emacs@gnu.org>]
* Re: Removing control M
[not found] ` <mailman.16341.1393660562.10748.help-gnu-emacs@gnu.org>
@ 2014-03-01 15:45 ` Dan Espen
0 siblings, 0 replies; 13+ messages in thread
From: Dan Espen @ 2014-03-01 15:45 UTC (permalink / raw)
To: help-gnu-emacs
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Dan Espen <despen@verizon.net>
>> Date: Fri, 28 Feb 2014 16:25:41 -0500
>>
>> To remove the control M's, just use Emacs normal find replace.
>> To type a ^M. type ^Q first.
>
> When (in what Emacs version) did you last try that, and it worked?
Don't exactly remember, it seems to me I did that not so long ago.
> If you visit a file normally, i.e. via "C-x C-f", you won't see any ^M
> characters at all. You will see a "(DOS)" indication in the mode line
> instead. This has been so since Emacs 20 at least.
I think that's right.
I might have encountered ^Ms in only part of the file,
not the whole file.
But the OP talked about seeing them and fixing them with Emacs.
I wonder if he saw them in Emacs and what version.
--
Dan Espen
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Removing control M
2014-02-28 20:16 Removing control M peaches20
` (2 preceding siblings ...)
[not found] ` <mailman.16317.1393620062.10748.help-gnu-emacs@gnu.org>
@ 2014-03-12 14:26 ` Ken Goldman
3 siblings, 0 replies; 13+ messages in thread
From: Ken Goldman @ 2014-03-12 14:26 UTC (permalink / raw)
To: help-gnu-emacs
I use eol-conversion.el, which permits conversion between Unix, DOS, and
Mac newline characters.
C-x RET / set-buffer-eol-conversion-mac
C-x RET : set-buffer-eol-conversion-unix
C-x RET \ set-buffer-eol-conversion-dos
It puts an entry on the Edit menu, if you like menus.
On 2/28/2014 3:16 PM, peaches20 wrote:
>
> I've transferred several dos files to unix. I now have the control M at tne
> end of the line. How does one remove this globally. I tried the dos2unis
> but that is not in my emacs commands.
^ permalink raw reply [flat|nested] 13+ messages in thread
[parent not found: <mailman.16316.1393619959.10748.help-gnu-emacs@gnu.org>]
* Re: Removing control M
[not found] <mailman.16316.1393619959.10748.help-gnu-emacs@gnu.org>
@ 2014-02-28 23:02 ` Joe Fineman
0 siblings, 0 replies; 13+ messages in thread
From: Joe Fineman @ 2014-02-28 23:02 UTC (permalink / raw)
To: help-gnu-emacs
peaches20 <watson1724@comcast.net> writes:
> I've transferred several dos files to unix. I now have the control M
> at tne end of the line. How does one remove this globally. I tried
> the dos2unis but that is not in my emacs commands.
I wrote this little utility some years ago & have used it ever since:
(defun ridm ()
"Remove intrusive CTRL-Ms from the buffer"
(interactive)
(save-excursion
(goto-char (point-min))
(replace-string "\C-m\C-j" "\C-j")))
--
--- Joe Fineman joe_f@verizon.net
||: Sexual morality is properly a department of hospitality. :||
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2014-03-12 14:26 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-28 20:16 Removing control M peaches20
2014-02-28 20:40 ` Jai Dayal
2014-02-28 20:43 ` peaches20
2014-02-28 20:44 ` Jai Dayal
2014-02-28 21:01 ` Bob Proulx
[not found] ` <mailman.16317.1393620062.10748.help-gnu-emacs@gnu.org>
2014-02-28 21:25 ` Dan Espen
2014-02-28 21:44 ` Mike Ray
2014-03-01 7:55 ` Eli Zaretskii
2014-03-01 8:31 ` Yuri Khan
2014-03-01 9:00 ` Eli Zaretskii
[not found] ` <mailman.16341.1393660562.10748.help-gnu-emacs@gnu.org>
2014-03-01 15:45 ` Dan Espen
2014-03-12 14:26 ` Ken Goldman
[not found] <mailman.16316.1393619959.10748.help-gnu-emacs@gnu.org>
2014-02-28 23:02 ` Joe Fineman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).