From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help Subject: Re: Removing control M Date: Fri, 28 Feb 2014 14:01:14 -0700 Message-ID: <20140228210114.GA6843@hysteria.proulx.com> References: <1393618592227-315636.post@n5.nabble.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1393621292 10235 80.91.229.3 (28 Feb 2014 21:01:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Feb 2014 21:01:32 +0000 (UTC) Cc: Help-gnu-emacs@gnu.org To: peaches20 Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 28 22:01:41 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WJUYu-0000NL-4c for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Feb 2014 22:01:40 +0100 Original-Received: from localhost ([::1]:53258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJUYt-0001Xw-P6 for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Feb 2014 16:01:39 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50174) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJUYe-0001WZ-DJ for Help-gnu-emacs@gnu.org; Fri, 28 Feb 2014 16:01:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WJUYW-00027J-N7 for Help-gnu-emacs@gnu.org; Fri, 28 Feb 2014 16:01:24 -0500 Original-Received: from joseki.proulx.com ([216.17.153.58]:56097) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WJUYW-00027B-GF for Help-gnu-emacs@gnu.org; Fri, 28 Feb 2014 16:01:16 -0500 Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 230CE21231; Fri, 28 Feb 2014 14:01:15 -0700 (MST) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id 00ABA2DC9B; Fri, 28 Feb 2014 14:01:14 -0700 (MST) Mail-Followup-To: peaches20 , Help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <1393618592227-315636.post@n5.nabble.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 216.17.153.58 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96229 Archived-At: 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 STRING NEWSTRING 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 c unix 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 c unix 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