Search code examples
sedcygwinnewlinelf

replace lf with cr-lf in text file Cygwin


I've got a Cygwin script that outputs stuff to a file. My only problem is that it always uses the \n "lf" line endings instead of \r\n "cr-lf". I want to either replace them or just get cygwin to always output \r\n for line endings.

I've tried the following two commands to no avail within the script.

unix2dos d:/temp.txt
sed -i -e 's/\n/\r\n/g' d:/temp.txt

Solution

  • You're specifying the path to unix2dos using a bizarre mix of Windows and Linux file endings.

    If you're calling it from a Windows command shell, use this:

    unix2dos d:\temp.txt
    

    If you're calling it from within Cygwin, or a Cygwin shell script or similar, use this:

    unix2dos /cygdrive/d/temp.txt