How to convert a text file's line termination from Windows/DOS to Unix?

4

Possible Duplicate:
Convert CRLF’s to line feeds on Linux

I have several scripts that produce a /bin/sh^M bad interpreter error message when they are run. I believe this is because they are formatted with the Windows/DOS line termination instead of the line termination expected by Unix/Linux (Ubuntu 9.04 for an embedded system in my case).

Is there an easy way to convert text files from the Windows/DOS format to the Unix format in a Linux environment?

Chrisbux

Posted 2009-09-10T00:15:05.583

Reputation: 548

Question was closed 2009-10-09T05:32:37.973

same question with some alternate answers: http://superuser.com/questions/52044/convert-crlfs-to-line-feeds-on-linux

– quack quixote – 2009-10-08T21:04:33.650

Answers

2

Molly7244

Posted 2009-09-10T00:15:05.583

Reputation:

That page claims this about the dos2unix tools: "These utilities are available only on Solaris systems." This answer explains how to get similar tools in Linux environment: http://superuser.com/questions/52044/convert-crlfs-to-line-feeds-on-linux/52140#52140

– Jonik – 2009-10-07T10:07:19.123

5

You can use the dos2unix utility for this.

dos2unix winfile.txt unixfile.txt

John T

Posted 2009-09-10T00:15:05.583

Reputation: 149 037

1Dammit! I wrote an app to do this for me in C#. Then again, it also converted ANSI to Unicode and back again, so it wasn't a complete waste. +1 – None – 2009-09-10T11:25:17.590

1@randolph: you implemented iconv in C#? – quack quixote – 2009-10-07T12:12:50.633