Method 1:
Use Linux iconv to convert the Utf-8 log to GBK encoded file, and then gbk the statistics in the environment. UTF8 () { log_file= "/lcims/crontab_shell/outfile/lan_wlan_wo/socketmain.log141114_lan1" LOG_FILE_TMP= "/ Lcims/crontab_shell/outfile/lan_wlan_wo/141114_lan1 " echo" utf-8-----" #only linux os use iconv iconv-f Utf-8-T gb2312 $LOG _file > $LOG _file_tmp echo "--------result" more $LOG _file_tmp| grep "Receive" |HEAD-4;} GBK () { echo "GBK----" log_file= "/lcims/crontab_shell/outfile/lan_wlan_wo/socketmain.log141114_wlan2" Lang=zh_cn.gb18030;export LANG; More $LOG _file| grep "Receive" |HEAD-4;} Utf8gbk
Method 2:
In the GBK environment, the GBK string is converted to Utf-8 string, and then the utf-8 log file is searched by Utf-8 string. UTF8 () { lang=zh_cn.utf8;export LANG; Log_file= "/lcims/crontab_shell/outfile/lan_wlan_wo/socketmain.log141114_lan1" LOG_FILE_TMP= "/lcims/crontab _shell/outfile/lan_wlan_wo/141114_lan1 " echo" utf-8-----"more $LOG _file| grep ' perl-e ' use Encode; $a =encode ("Utf-8", Decode ("gb2312", "receive"));p rint $a ' |head-4;} Utf8
Shell script GBK Environment Search Utf-8 Log