Converting Line Endings

I had a text file on my Linux server that I needed to convert from Windows line endings (CRLF) to Unix line endings (LF) and had to google how to do it. I ran across a good way to handle it that can also be used for other things so I wanted to post it here to help me remember:

tr -d '\r' < infile > outfile to go from Windows -> Unix (note: don't use the same file name or it will be empty)
awk 'sub("$", "\r")' unixfile.txt > winfile.txt to go from Unix -> Windows as tr can not go from Unix to Windows.

Leave a Reply

Your email address will not be published. Required fields are marked *

18 + 14 =