学习perl过程中开始退回来重新系统的学习unix基本知识,此程序为在看"sed & awk"过程中根据C语言版改写,希望有人能用得到。
#unl2xls:convert unl files to xls files
#write by huangtao
UNLToXls() {
awk '
BEGIN {
FS="|"
print ""
print ""
#确保中文能正常显示
print "
"
print ""
print ""
print "
"
}
{
for(n=1;n<=NF-1;n++) {
if (n==1) print ""
#将0开头字符串强制设置为文本格式
if ($n ~ /^0[0-9]+$/) printf("%s | \n",$n)
else printf("%s | \n",$n)
if (n==NF-1) printf("
\n")
}
}
END {
print "
"
print "
"
print ""
}
' $OldFileName
rm $OldFileName
}
if [ -z "$1" ];then
echo "Usage: $0 file1.unl [file2.unl]..."
exit
fi
for OldFileName in $* ; do
if [ -s $OldFileName ];then
NewFileName=${OldFileName%unl}xls
UNLToXls $OldFileName >$NewFileName
else rm $OldFileName
fi
done
#tar cf `date +"%Y%m%d%H%M"`.rar *.xls && rm *.xls
阅读(1303) | 评论(0) | 转发(0) |