Tuesday, February 7, 2012

Convert Windows Line Endings (CRLF) to Unix (LF) Line Endings

While I was doing an svn merge I got into a problem where both files have different line ending and It was hard to detect the exact differences in the files, so the simplest solution is to match the line endings of both files.

I googled for couple of minutes, tired different solution and I found this solution the easiest one : (Basically I am removing '\r' from the line endings in the Windows version)

tr -d '\r' < top.jsp > top2.jsp


The tr utility copies the standard input to the standard output with substitution or deletion of selected characters.


-d - delete the characters sequences in the string ('\r' in my case) from the output file


< top.jsp > is the file with Windows (CRLF) or the source file


top2.jsp is the output file

You can find more information here :
https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/tr.1.html

Hope that helps you!


No comments: