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 upgrade G4520G6 (B7149) Ffirmware

 G4520G6 firmware process Web GUI mode: CPLD -> BMC -> BIOS BMC Out of band (Redfish/BMC Web) : CPLD: *.jed.tar (System need power off...