我正在使用脚本命令来记录终端中的所有内容。但是当我打开生成的文件时,它有很多垃圾字符。任何人都可以帮助我从文件中删除这些垃圾字符或任何其他替代方法吗?
该文件如下所示:
ossvm10(0)> ls -lrt /usr/opt/temip/mmexe/mcc_fcl_pm.exe^M
^[[00m-rwxr-xr-x 1 root root 387517 Feb 18 2013 ^[[00;32m/usr/opt/temip/mmexe/mcc_fcl_pm.exe^[[00m^M
^[[m^[]0;temip@ossvm10:/home/dharmc^G[/home/dharmc]^M
ossvm10(0)> script -a unit_testing_TEMIPTFRLIN_00202_CR#9961.txtsum /usr/opt/temip/mmexe/mcc_fcl_pm.exe^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^[[1P^H^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^H^[[1P^[[1P^H^G^G^G^G^G^G^G^G^M
06046 379^M
^[]0;temip@ossvm10:/home/dharmc^G[/home/dharmc]^M
答案1
您可以简单地运行:
dos2unix <filename>
这将从^M
文件中删除所有字符。 ^M是DOS环境下生成的回车符。该命令dos2unix
只是将文件从 DOS 格式转换为 Unix 格式。
要删除^H
和^G
字符,请使用sed
:
sed -i 's/\^H//g;s/\^G//g' <filename>