The below information was shamelessly copied, word for word, from http://mike.kruckenberg.com 🙂
Changing end-of-line Mode in Emacs (replaces ^M line return)
Every now and then I run into this. I export CSV data from Excel and find that when trying to use it in other places the line-returns aren’t quite right and unix tools like ‘less’ and ‘pico’ think the file is one long line, with ^M in places where a line-return should be.
Wanting to replace the ^M I open the file in emacs, which is smart enough to go into Mac mode and show the file with the correct line returns.
I poked around and found that if the ^M is showing up in emacs this sequence will replace them:
1. M-% (esc % on Mac X11 Emacs)
2. ctrl-q ctrl-m RET (specifies ^M to replace)
3. ctrl-q ctrl-j RET (specifies a line return as the replacement)
4. ! (runs the replace on the entire file)
But in my case the ^M isn’t showing because emacs knows to use ^M for a line return on mac. So what I need to do is change the end-of-line, which is specified in buffer-file-coding-system. You can change the file from Mac mode to unix with this command:
M-x set-buffer-file-coding-system RET unix
When you do that emacs suggests using this shortcut:
ctrl-x RET f unix RET
Save the file after changing the end-of-line and all is good in my other unix utilities.
One Response to How to use emacs to replace Mac carriage returns (the ^M line endings, and that includes even the “stubborn” ones!)…
Leave a Reply to Alan Cancel reply
-
Categories
- Android Development
- Bash
- C programming
- dpkg/apt-get
- drupal
- Emacs
- Git
- Java
- Linux administration
- Linux device drivers
- Linux Gaming
- Linux kernel
- Linux Networking
- Linux on Windows
- Linux printing
- Linux sound and ALSA
- Package Managers
- Programming
- RPM
- Shell and environment
- Tips and tricks
- Uncategorized
- VirtualBox
- Virtualization
- web development
- wine
- WMaker
- Wordpress Tips
- X Window System
- XFCE
-
Articles
- August 2020
- August 2019
- May 2019
- July 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- April 2016
- March 2016
- December 2015
- November 2015
- September 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- October 2014
- February 2014
- January 2014
- November 2013
- October 2013
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
-
Meta
Cloud
audio bash boot compile C programming cups drupal emacs etc Fedora git grep how to httpd init kernel libc linux linux partition localtime login make mount mp3 mysql networking oracle package managers password phpMyAdmin programming rpm shell sql vbox version control system virtual box vm web server wordpress www xargs xfce xwin yum
… or …
Just use dos2unix / unix2dos commands to fix the EOL characters in the file to your liking.
… or …
You can change file’s encoding to e.g. ‘unix’ with
M-x set-buffer-file-coding-system
.. or its shortcut
Ctrl-X, f
, like thisC-x RET f unix