博客是我工作的好帮手,遇到困难就来博客找资料
分类: 系统运维
2015-02-09 14:56:56
shell源码
# !/bin/sh
file_input='txt.log'
file_output='txt2html.html'
td_str=''
function create_html_head(){
echo -e "
}
function create_table_head(){
echo -e "1
">"
}
function create_td(){
# if [ -e ./"$1" ]; then
echo $1
td_str=`echo $1 | awk 'BEGIN{FS="|"}''{i=1; while(i<=NF) {print ""$i"";i++}}'`
echo $td_str
# fi
}
function create_tr(){
create_td "$1"
echo -e "
$td_str
" >> $file_output
}
function create_table_end(){
echo -e ""
}
function create_html_end(){
echo -e ""
}
function create_html(){
rm -rf $file_output
touch $file_output
create_html_head >> $file_output
create_table_head >> $file_output
while read line
do
echo $line
create_tr "$line"
done < $file_input
create_table_end >> $file_output
create_html_end >> $file_output
}
create_html
cat cvshtml-common.sh
#!/bin/sh
#通用cvs转html脚本
#调用格式:./cvshtml-common.sh "列名1,列名2,列名3..." 文件名
CSVFILE=$2
TITLE=$1
TD_STR=''
#this function create a
create_td()
{
#TD_STR2=`echo $1 | awk -F, '{if($6==1 || $7==1)for(i=1;i<=NF;i++)print "
#TD_STR3=`echo $1 | awk 'BEGIN{FS=","}{i=1; while(i<=NF) {print "
count=$(($2%2))
if [[ $count -eq 0 ]]; then
TD_STR=`echo $1 | awk -F, '{for(i=1;i<=NF;i++)print "
else
TD_STR=`echo $1 | awk -F, '{for(i=1;i<=NF;i++)print "
fi
}
#this function create a row html script(
create_tr()
{
create_td $1 $2
echo "
}
#create html script head
create_html_head()
{
echo "
"}
#create html script end
create_html_end()
{
echo " "
#echo "
}
create_table_head()
{
echo "
(免费)日期 | ""$i" | ";}'`
}
create_html_head
create_table_head
line_count=1;
while read LINE
do
#echo "$LINE"
line_count=$(($line_count+1))
create_tr $LINE $line_count
done < $CSVFILE
create_table_end
create_html_end
cat /home/haoren/xiaofei-paihang-cvshtml2.sh
#!/bin/sh
CSVFILE=$1
TD_STR=''
day2=`date +"%Y-%m-%d"`
day3=`date -d"1 days ago" +%Y-%m-%d`
day4=`date -d"1 years ago" +%Y-%m-%d`
#this function create a
create_td()
{
TD_STR2=`echo $1 | awk -F, '{if($6==1 || $7==1)for(i=1;i<=NF;i++)print "
TD_STR3=`echo $1 | awk 'BEGIN{FS=","}{i=1; while(i<=NF) {print "
}
#this function create a row html script(
create_tr()
{
create_td "$1"
# echo "
#echo "
echo "
}
#create html script head
create_html_head()
{
#echo "
`date "+%Y%m%d"` | "
#echo ''
#echo ''
#echo '
#echo "
"#echo "
下面是赛车数据
"echo "
"echo "
ID | "排行 | "消费号 | "收费票 | "免费票 | "绰号 | "
}
create_table_head()
{
echo #"
}
create_html_head
create_table_head
while read LINE
do
# echo "$LINE"
create_tr "$LINE"
done < $CSVFILE
create_table_end
create_html_end