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:

To go from Windows -> Unix
(note: don't use the same file name or it will be empty)

tr -d '\r' < infile > outfile 

To go from Unix -> Windows.

awk 'sub("$", "\r")' unixfile.txt > winfile.txt 

Leave a Reply

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

three + 9 =