How to remove ^ M in emacs

How to delete characters ^Min Emacs?

It does not work using dos2unix filenameor unix2dos filename.

This is what happened when I use the command cat -A filename, because usually I don't see characters ^M.

Please explain this in simple words ... and in detail ...

cat -A ABC.sh
#!/bin/csh -f^M$
^M$
^M$
set input = `ls -1 *.py`^M$
echo $input^M$
+4
source share
2 answers

[I searched for a duplicate, but did not find a replacement (instead of prevention, etc.). If there is one, then this or the one that should be closed.]

In Emacs, go to the character file ^M. Go to the beginning of the file ( M-<), then:

M-x replace-string C-q C-m RET RET

, , Control + q, Control + m, Enter. , , Enter ( ).

+4

(defun delete-carrage-returns ()
  (interactive)
  (save-excursion
    (goto-char 0)
    (while (search-forward "\r" nil :noerror)
      (replace-match ""))))

, , , .

+2

Source: https://habr.com/ru/post/1540967/


All Articles