Possible Duplicate:
Remove carriage return in Unix
I am reading some data generated by an external third party. I have noticed that the ASCII text in the file is interspersed with ^M characters, which I believe is character 13 in ASCII and represents a carriage return without linefeed.
Is there a one liner I can use to strip the ^M characters from the file?
I am running on Linux (Ubuntu).
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.
Escape characters are used to remove the special meaning from a single character. A non-quoted backslash, \, is used as an escape character in Bash.
Note: Remember how to type control M characters in UNIX, just hold the control key and then press v and m to get the control-m character.
Viewing the certificate files in Linux shows ^M characters appended to every line. The file in question was created in Windows and then copied over to Linux. ^M is the keyboard equivalent to \r or CTRL-v + CTRL-m in vim.
You can use sed like this:
sed -i.bak 's/^M$//' infile.txt
To type ^M
, you need to type CTRL-V
and then CTRL-M
.
OR
dos2unix infile.txt file2.txt ....
OR
man dos2unix
for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With