What is the simplest way to remove all the carriage returns \r from a file in Unix?
What is the simplest way to remove all the carriage returns \r from a
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m going to assume you mean carriage returns (CR,
"\r",0x0d) at the ends of lines rather than just blindly within a file (you may have them in the middle of strings for all I know). Using this test file with a CR at the end of the first line only:dos2unixis the way to go if it’s installed on your system:If for some reason
dos2unixis not available to you, thensedwill do it:If for some reason
sedis not available to you, thenedwill do it, in a complicated way:If you don’t have any of those tools installed on your box, you’ve got bigger problems than trying to convert files 🙂