Pages

Sunday, April 22, 2012

Remove carriage return ^M from a text file

Sometimes I have text files with a trailing carriage return character like this:

# vi file.txt
...
"foo"^M
"foo"^M
...

To remove them I use sed (when dos2unix is not available):

# cat file.txt | sed 's/\r//' > new.txt
# vi new.txt
...
"foo"
"foo"
...

No comments:

Post a Comment