[Top][All Lists]

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

Re: Removing control M

From: Bob Proulx
Subject: Re: Removing control M
Date: Fri, 28 Feb 2014 14:01:14 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

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


reply via email to

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