Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Windows file format to Linux format

I am using Linux machine for development and then deploying my script files to Azure function app which is a Windows machine.

Then I am copying shell script files to wasb from Azure function app.

I am getting following error when running shell script in Edge node on Azure HDI cluster

$'\r': command not found

My script files are not executed properly.

What is the best way to convert dos2unix option in C# Azure function?

like image 868
Galet Avatar asked Feb 01 '26 05:02

Galet


2 Answers

You could upload your file to Linux and change file format.

dos2unix <filename>

Another easy solution is that if you install Notepad++, it supports automatic conversion format to Unix(LF).

enter image description here

like image 105
Shui shengbao Avatar answered Feb 02 '26 19:02

Shui shengbao


You don't have to do anything special to read a file that contains Unix-style newlines (\n) instead of \r\n. .NET IO methods treat both as newlines.

You could write

var lines-File.ReadAllLines("myUnixText.txt");

or

using(var reader=File.OpenText("myUnixText.txt"))
{
    string line;
    while( (line=reader.ReadLine()) !=null)
    {
        // Do something
    }
}

to read lines whether the line ending is \r or \n

To prove it :

var numbers = new[]{1,2,3,4,5,6};
var lines=String.Join("\n",numbers);
File.WriteAllText("myUnixText.txt",lines);

var newLines=File.ReadAllLines("myUnixText.txt");

Debug.Assert(newLines.Length==6);

Even though only a single string was written, File.ReadAllLines read 6 lines from the file

like image 22
Panagiotis Kanavos Avatar answered Feb 02 '26 19:02

Panagiotis Kanavos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!