tr '\r' '\n' < file.txt > file.txt
I just had to do this on a file that someone shared with me. Next maybe we'll look at how I chopped up and hacked that file with grep and cut :)
Paul Asadoorian
PaulDotCom
Davide Brini points out that there are a couple of problems with the solution above:
- The output redirections here "... <file.txt >file.txt" are going to leave you with an empty file. That's because the ">file.txt" truncates the file before "<file.txt" reads any data from it. What you need to do instead is something like "... <file.txt >newfile.txt"
- Paul's tr command results in double newlines for DOS-formatted files whose lines typically end with "\r\n". A more correct solution would be "sed 's/\r$//' file.txt >newfile.txt"
As Davide also points out, there's also the dos2unix utility which is an Open Source tool that's often found in Unix-like OSes.