I am trying to use hexl mode to manually remove some special chars from a text file and don't see how to delete anything in hexl mode.
What I really want is to remove carriage return and keep linefeed characters. Is Hexl mode the right way to do this?
From http://www.xsteve.at/prg/emacs/xsteve-functions.el:
Add this to your
.emacs
and run it viaM-x xsteve-remove-control-M
or bind it to a easier key. It will strip the^M
s in anymode.You don't need to use hexl-mode. Instead:
The point is that even if you don't how to enter what you are trying to replace, you can always select/copy it.
Assuming you want a DOS encoded file to be changed into UNIX encoding, use M-x set-buffer-file-coding-system (C-x RET f) to set the coding-system to "unix" and save the file.
If you want to remove a carriage return (usually displayed as
^M
) and leave the line feed. You can just visit the file w/out any conversion:Because a file with carriage returns is generally displayed in DOS mode (hiding the carriage returns). The mode line will likely display
(DOS)
on the left side.Once you've done that, the
^M
will show up and you can delete them like you would any character.Oops. That ^J^M needs to be entered as two literal characters. Use
c-q
c-j
,c-q
c-m
and for the replacement string, usec-q
c-j
.No need for hexl-mode for this. Just do a global-search-and-replace of ^J^M with ^J Works for me. :) Then save the file, kill the buffer, and revisit the file so the window shows the new file mode (Unix vs DOS).