Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a EOL converter for Windows with Explorer integration so that I can simply right-click on a file and select which type of line-ending I want to convert to. I often run into files which have inconsistent line-endings, and Subversion refuses and commit those until I fix them.

share|improve this question
    
Would you mind to share a sample file? This way I can test some solutions easier. –  nixda Feb 11 '13 at 13:38
    
Here's a file with mixed line-endings: dl.dropbox.com/u/2113034/crlf.txt –  JesperE Feb 12 '13 at 9:13

1 Answer 1

up vote 1 down vote accepted

With this solution you can right click any file and convert from LF (Unix, Linux, Mac OS X) to CR+LF (Windows) line breaks

  1. Create a .CMD file somewhere and paste the following code

    SET "output=%~1"
    SET "search=\%~n1."
    SET "replace=\%~n1 (CR+LF)."        
    CALL SET "output=%%output:%search%=%replace%%%"
    
    TYPE "%~1" | FIND "" /V > "%output%"
    

    Line 1-4 are only for renaming the output file correctly and append "(CR+LF)" to the filename
    You can read more about batch arguments here.
    The key is that TYPE knows how to read LF line endings

  2. Save a shortcut from the .CMD file in your sendto folder (Win+R » shell:sendto )

For additional conversion directions, download the command line utility dos2unix and use it the same way as shown above. Just replace the last line. The syntax is always the same.

dos2unix "%~1" "%output%"
mac2unix "%~1" "%output%"  
unix2dos "%~1" "%output%"  
unix2mac "%~1" "%output%"  

Notepad++ has a handy EOL conversion option but I guess you already know that and it is not comfortable and fast enough to open, convert and save the file. Unfortunately notepad++ doesn't provide command line switches for that specific task.

enter image description here

share|improve this answer
    
Unfortunately Notepad++ cannot convert files with mixed line-endings. If there are both LF and CRLF in a file, it will refuse to directly convert to Windows. You have to first convert to Unix, and then back to Windows. Annoying. –  JesperE Feb 12 '13 at 9:04
    
I opted for the "unix2dos" variant. The "TYPE" variant didn't work. Will it correctly detect file with mixed EOL conventions? –  JesperE Feb 12 '13 at 9:18
    
Hmm, I tested the TYPE method in just this second with your test file. It worked pretty well. Here is a proof screen for the TYPE method –  nixda Feb 12 '13 at 9:19
    
Ok. Thanks, anyway. –  JesperE Feb 12 '13 at 9:20
    
I am curious about what went wrong in your test setup. I can't reproduce your behavior. Can you explain it more? –  nixda Feb 12 '13 at 9:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.