Thursday, August 19, 2021

How to remove ^M in Linux

方法一:

    dos2unix [-kn] filename [new filename]

Ex:

[root@localhost ~]# dos2unix -k -n diff.log newdiff.log

dos2unix: converting file diff.log to file newdiff.log in UNIX format

*註:也可以反過來把UNIX格式文件轉換為DOS格式文件,unix2dos [-kn] filename [new filename]。


方法二:

    直接用vi/vim開啟文件,進入指令列命令模式

    :%s/^M//g    其中^請按Ctrl+V,M請按Ctrl+M。


方法三:

    使用tr指令直接清除掉斷行字元,cat filename | tr -d '\r' > new filename

[root@localhost ~]# cat diff.log | tr -d '\r' > newdiff.log


*註:在Windows底下也可以轉換文件格式,像是UltraEdit或是Pspad都有格式轉換功能。

No comments:

Post a Comment

How to fix gpu_burn compiler failure issue

System Environment: Ubuntu 22.04 LTS Server CUDA v12.0 GPU: RTX-4080 (driver 525.85.05) AP: GPU_Burn v1.1 Symptom: met error in make gpu_bur...