66

TexPad is creating it. I know that it is under some deadkey. I just cannot remember it is name.

The blue character:

enter image description here

I just want to mass remove them from my document.

How can you type it?

Mikel
  • 56,387
  • 13
  • 130
  • 149
Léo Léopold Hertz 준영
  • 6,788
  • 29
  • 91
  • 193
  • 1
    Related: [Why are special characters such as “carriage return” represented as “^M”?](http://superuser.com/q/763879/53590) on Super User. – user Jun 05 '14 at 22:18

4 Answers4

79

It is known as carriage return.

If you're using vim you can enter insert mode and type CTRL-v CTRL-m. That ^M is the keyboard equivalent to \r.

Inserting 0x0D in a hex editor will do the task.

How do I remove it?

You can remove it using the command

perl -p -i -e "s/\r//g" filename

As the OP suggested in the comments of this answer here, you can even try a `

dos2unix filename

and see if that fixes it.

As @steeldriver suggests in the comments, after opening the vim editor, press esc key and type :set ff=unix.

References

https://stackoverflow.com/questions/1585449/insert-the-carriage-return-character-in-vim

https://stackoverflow.com/a/7742437/1742825

-ksh: revenue_ext.ksh: not found [No such file or directory]

Paulo Tomé
  • 3,754
  • 6
  • 26
  • 38
Ramesh
  • 38,687
  • 43
  • 140
  • 215
8

Code

sed -i 's/^M//' filename.txt

While typing ^M in the command, do not use ^M as that only inserts what is displayed, not what causes it to be displayed; use CtrlV CtrlM.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
Kashyap
  • 79
  • 1
  • 1
3

you can also do this with sed

 sed -i "s/\r//g" filename
k_vishwanath
  • 198
  • 7
0

As Ramesh notes, CTRL+V CTRL+M should get you the literal character - though you're not limited to doing this only in vim - you should be able to do the same on any canonical mode tty.

cat ./file | tr -d '\r' >./file

...might do the job.

Ramesh
  • 38,687
  • 43
  • 140
  • 215
mikeserv
  • 57,448
  • 9
  • 113
  • 229
  • 1
    you're reading from and writing to the same file, would this not cause a problem – iruvar Jun 05 '14 at 19:20
  • @1_CR Im reading from the `|pipe` file. Its true, an intermediate tmp file would be more robust - but the buffer in the pipe should be enough. Still, in case it isnt, `tr -d '\r' <./file\n$(cat ./file)\nFILE\n` would be a sure thing - provided the file contains no `\000` characters, that is. – mikeserv Jun 05 '14 at 19:28
  • This will more than likely erase `./file` before `cat` has a chance to read it. All commands of a pipeline are launched in parallel and redirections are processed by the shell **before** the affected command is executed. – jlliagre Feb 23 '17 at 08:33
  • @mikeserv re the heredoc-containing-`$(cat)` fix: or (significant) trailing empty lines or unterminated last line, or more data than fits in available memory. `(rm file; tr -d '\r' >file) – dave_thompson_085 Feb 23 '17 at 12:37