0

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
Ian
  • 4,169
  • 3
  • 37
  • 62

2 Answers2

1

Your unix2dos call should work. Are you getting some kind of error?

The Cygwin installer has an option for selecting the default line ending convention (DOS or Unix), although it might only show it during a new installation -- I don't remember offhand.

jjlin
  • 4,462
  • 1
  • 30
  • 23
  • No, no error. I can even put the unix2dos call before the last command, and the last command still works. – Ian Feb 13 '12 at 23:53
  • So you're saying it seems to do nothing? What if you run it manually? You should see a message like `dos2unix: converting file d:/temp.txt to Unix format ...` -- do you? – jjlin Feb 13 '12 at 23:56
  • Well, never mind. I call my script from another script and then add the unix2dos at the end of the outer script and it works. – Ian Feb 14 '12 at 00:05
  • The Cygwin installer has no such option for line ending conversion. Are you thinking of the Windows Git installer (or something similar) which runs an old version of Cygwin, and does? – me_and Feb 24 '12 at 09:54
  • No, I was thinking of an older version of the Cygwin installer. You're right, the current Cygwin installer doesn't have this option anymore. – jjlin Feb 24 '12 at 19:12
0

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
me_and
  • 15,158
  • 7
  • 59
  • 96