What is the simplest way to remove all the carriage returns \\r
from a file in Unix?
The simplest way on Linux is, in my humble opinion,
sed -i 's/\r$//g'
The strong quotes around the substitution operator 's/\r//'
are essential. Without them the shell will interpret \r
as an escape+r and reduce it to a plain r
, and remove all lower case r
. That's why the answer given above in 2009 by Rob doesn't work.
And adding the /g
modifier ensures that even multiple \r
will be removed, and not only the first one.