Removing control M

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Removing control M

peaches20
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
Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Jai Dayal
dos2unix is not an emacs command, but a shell command.


On Fri, Feb 28, 2014 at 3:16 PM, peaches20 <[hidden email]> 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.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

peaches20
I did use dos2unix at the promt and got the command not found error.  I typed

dos2unix testm.tex

Any other suggestions?

Thanks,

Peaches
Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Jai Dayal
well, install the dos2unix utility, then.


On Fri, Feb 28, 2014 at 3:43 PM, peaches20 <[hidden email]> wrote:

> I did use dos2unix at the promt and got the command not found error.  I
> typed
>
> dos2unix testm.tex
>
> Any other suggestions?
>
> Thanks,
>
> Peaches
>
>
>
> --
> View this message in context:
> http://emacs.1067599.n5.nabble.com/Removing-control-M-tp315636p315639.html
> Sent from the Emacs - Help mailing list archive at Nabble.com.
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Bob Proulx
In reply to this post by peaches20
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

Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Dan Espen-4
In reply to this post by peaches20
>>>>> "Jai" == Jai Dayal <[hidden email]> writes:

    Jai> dos2unix is not an emacs command, but a shell command.
    Jai> On Fri, Feb 28, 2014 at 3:16 PM, peaches20 <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Mike Ray
On 28/02/2014 21:25, Dan Espen wrote:

>>>>>> "Jai" == Jai Dayal <[hidden email]> writes:
>      Jai> dos2unix is not an emacs command, but a shell command.
>      Jai> On Fri, Feb 28, 2014 at 3:16 PM, peaches20 <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Joe Fineman
In reply to this post by peaches20
peaches20 <[hidden email]> 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    [hidden email]

||:  Sexual morality is properly a department of hospitality.  :||
Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Eli Zaretskii
In reply to this post by Dan Espen-4
> From: Dan Espen <[hidden email]>
> 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.

Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Yuri Khan-2
On Sat, Mar 1, 2014 at 2:55 PM, Eli Zaretskii <[hidden email]> 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.

Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Eli Zaretskii
> Date: Sat, 1 Mar 2014 15:31:41 +0700
> From: Yuri Khan <[hidden email]>
> Cc: "[hidden email]" <[hidden email]>
>
> On Sat, Mar 1, 2014 at 2:55 PM, Eli Zaretskii <[hidden email]> 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.


Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Dan Espen-4
In reply to this post by Dan Espen-4
Eli Zaretskii <[hidden email]> writes:

>> From: Dan Espen <[hidden email]>
>> 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
Reply | Threaded
Open this post in threaded view
|

Re: Removing control M

Ken Goldman-2
In reply to this post by peaches20
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.