shell ASCII text转码

1、现象:

cat 可以正常显示,vi却乱码

2、

[[email protected]_113 ~]# file phpdba.txt
phpdba.txt: ASCII text, with escape sequences

3、转码shell脚本

#!/bin/bash
CSI=’\x1b\[‘            # the two-character csi escape sequence .Esc [., followed by i
Rp='[0-9:;<=>?]’        # an optional sequence of parameter bytes in the range x30.x3F,
Ri='[- !\”#$%&’\”()*+,./]’ # an optional sequence of intermediate bytes in the range x20.x2F,
Rf='[]@A-Z[\\^_`a-z{|}~]’   # and a final byte in the range x40.x7e.
# The set of standard control sequence functions are defined in Ecma-48 / ISO/IEC 6429.
cat phpdba.txt | sed -e ‘s/'”$CSI$Rp”‘*'”$Ri”‘*'”$Rf”‘//g’ > phpdbautf8.txt

utf8格式转换成功

此条目发表在技术生涯分类目录,贴了, 标签。将固定链接加入收藏夹。