How to remove ctrl M characters when transferring files from a window to unix using Tectia?

I want to transfer files from Windows to Unix using Tectia. But the problem is when these files are transferred (both in Ascii and in binary mode) and opened using VI, we get ^ M characters. I searched for this, but solutions should remove these ^ M characters when files are transferred with using the utility. Is there a way to prevent these ^ M characters from appearing in the first place.

+13
source share
10 answers

Thank you all for your help. I solved this problem using a workaround. Windows uses CR + LF (\ r \ n) as the end of the line & Unix uses LF (\ n) as the end of the line. I took the Windows file and replaced CR + LF (\ r \ n) with LF (\ n) in the code itself without any utility. This made the file compatible for the Unix system, and then I transferred the file using SFTP and it worked on Unix.

+1
source

How did I manage to remove it in vi editor:

  • After :%s/ then press ctrl + V , then ctrl + M. It will give you ^M
  • Then //g (it will look like this:: :%s/^M ) press Enter to delete everything.

Good luck

+20
source

You can install and use dos2unix . After installation, just run:

 >dos2unix yourfile.txt 
+12
source

If you just need to remove the ^M characters (don't 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 
+11
source

Another trick to remove Ctrl + M in vi editor:

 :%s/^V^M//g 

To get more trick delete Ctrl + M characters

+5
source

Try the following in your terminal (you may need to install it first):

 fromdos <your-file> 
+3
source
 :%s/^V^M// 
  • g not required at all.

  • %s - find and replace the text you want to replace

  • ^V^M , which should be replaced with "must be after a double slash", will keep it empty if you want to replace anything

+1
source

Try

 tr -d '\015' <INPUT_FILE > OUTPUT_FILE 
0
source

tr '\015' '\n' < /tmp/file-with-ctrlm.txt > /tmp/no-ctrlm.txt

  • This command uses the ASCII code CtrlM and replaces all CtrlM with newline characters.
  • It avoids Ctrl-V, Ctrl-M and works on Mac too.
0
source

For me, this is the only thing that will work .. not Unix2dos or anything ...

sed -e 's / \ x0D // g'

link:

Hexadecimal 0a, a control character as opposed to a printed character, is called line feed.

Hex 0d is called carriage return.

0
source

Source: https://habr.com/ru/post/1435213/


All Articles