Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - how to remove ctrl M characters when transferring files from windows to unix using Tectia?

In a C# module, I want to transfer files from Windows to Unix using Tectia. But the problem is when these files are transferred(Ascii or Binary mode both) and opened using VI editor we get ^M characters. I searched about this but the solutions are to remove these ^M characters after the files are transferred using utilites. Is there any way that these ^M characters do not appear in the first place. Is there any option to have a workaround in code before sending these files?

like image 916
Ravi Goklani Avatar asked Sep 20 '12 07:09

Ravi Goklani


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.


2 Answers

How I was able to remove it in vi editor:

  • After :%s/ then press ctrl+V then ctrl+M. This will give you ^M
  • Then //g (will look like: :%s/^M ) press Enter should get all removed.

Good luck!

like image 175
Rajesh Avatar answered Oct 15 '22 10:10

Rajesh


If you just need to remove the ^M characters (not replace them with \n):

sed -i -e 's/\r//g' yourfile.txt

If you want to replace them with \n:

sed -i -e 's/\r/\n/g' yourfile.txt
like image 22
JellicleCat Avatar answered Oct 15 '22 09:10

JellicleCat