Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1736695
  • 博文数量: 636
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 3950
  • 用 户 组: 普通用户
  • 注册时间: 2014-08-06 21:58
个人简介

博客是我工作的好帮手,遇到困难就来博客找资料

文章分类

全部博文(636)

文章存档

2024年(5)

2022年(2)

2021年(4)

2020年(40)

2019年(4)

2018年(78)

2017年(213)

2016年(41)

2015年(183)

2014年(66)

我的朋友

分类: 系统运维

2015-02-09 14:56:56

shell源码

  1. # !/bin/sh  

  2.   

  3. file_input='txt.log'  

  4. file_output='txt2html.html'  

  5.   

  6. td_str=''  

  7.   

  8. function create_html_head(){  

  9.     echo -e "  

  10.           

  11.             

    $file_input

    "  


  12. }  

  13.   

  14. function create_table_head(){  

  15.     echo -e "1">"  

  16. }  

  17.   

  18. function create_td(){  

  19. #    if [ -e ./"$1" ]; then  

  20.         echo $1  

  21.         td_str=`echo $1 | awk 'BEGIN{FS="|"}''{i=1; while(i<=NF) {print ""$i"";i++}}'`  

  22.         echo $td_str  

  23. #    fi  

  24. }  

  25.   

  26. function create_tr(){  

  27.     create_td "$1"  

  28.     echo -e "  

  29.         $td_str  

  30.     " >> $file_output  

  31. }  

  32.   

  33. function create_table_end(){  

  34.     echo -e ""  

  35. }  

  36.   

  37. function create_html_end(){  

  38.     echo -e ""  

  39. }  

  40.   

  41.   

  42. function create_html(){  

  43.     rm -rf $file_output  

  44.     touch $file_output  

  45.   

  46.     create_html_head >> $file_output  

  47.     create_table_head >> $file_output  

  48.   

  49.     while read line  

  50.     do  

  51.         echo $line  

  52.         create_tr "$line"   

  53.     done < $file_input  

  54.   

  55.     create_table_end >> $file_output  

  56.     create_html_end >> $file_output  

  57. }  

  58.   

  59. create_html  



  60. cat  cvshtml-common.sh

    #!/bin/sh

    #通用cvs转html脚本

    #调用格式:./cvshtml-common.sh "列名1,列名2,列名3..." 文件名

    CSVFILE=$2

    TITLE=$1

    TD_STR=''


    #this function create a block

    create_td()

    {

            #TD_STR2=`echo $1 | awk -F, '{if($6==1 || $7==1)for(i=1;i<=NF;i++)print ""$i""; else for(i=1;i<=NF;i++)print ""$i""}'`

            #TD_STR3=`echo $1 | awk 'BEGIN{FS=","}{i=1; while(i<=NF) {print ""$i"";i++}}'`

        count=$(($2%2))

        if [[ $count -eq 0 ]]; then

            TD_STR=`echo $1 | awk -F, '{for(i=1;i<=NF;i++)print ""$i"";}'`

        else

            TD_STR=`echo $1 | awk -F, '{for(i=1;i<=NF;i++)print ""$i"";}'`

        fi

    }

    #this function create a row html script(block).

    create_tr()

    {

        create_td $1 $2

        echo  "$TD_STR"

    }

    #create html script head

    create_html_head()

    {

            echo ""

    }

    #create html script end

    create_html_end()

    {

            echo  " "

            #echo  "

    "

    }

    create_table_head()

    {

            echo "

    "

            #echo "

    "

            TR_TITLE=`echo $TITLE|awk -F, '{for(i=1;i<=NF;i++)print "

    ";}'`

            echo  "

    $TR_TITLE"

    }

    create_table_end()

    {

            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 block

    create_td()

    {

            TD_STR2=`echo $1 | awk -F, '{if($6==1 || $7==1)for(i=1;i<=NF;i++)print ""$i""; else for(i=1;i<=NF;i++)print ""$i""}'`

            TD_STR3=`echo $1 | awk 'BEGIN{FS=","}{i=1; while(i<=NF) {print ""$i"";i++}}'`

    }

    #this function create a row html script(block).

    create_tr()

    {

            create_td "$1"

    #        echo  "$TD_STR1"

            #echo  "$TD_STR2"

            echo  "$TD_STR3"

    }

    #create html script head

    create_html_head()

    {

            #echo "

    "

            #echo "

    "

            #echo "

    `date "+%Y%m%d"`
    "

            #echo ''

            #echo ''

            #echo '赛车统计'

            #echo ""

            #echo "

    下面是赛车数据

    "

            echo ""

            echo "

    "

    #       echo "

    "

            echo "

    "

            echo "

    "

            echo "

    "

            echo "

    "

            echo "

    "

    }

    #create html script end

    create_html_end()

    {

            echo  ""

            echo  "

    ID 排行 消费号 收费票 免费票 绰号
    "

    }

    create_table_head()

    {

            echo  #"

    "

    }

    create_table_end()

    {

            echo  "

    "

    }

    create_html_head

    create_table_head

    while read LINE

    do

    # echo "$LINE"

    create_tr "$LINE"

    done < $CSVFILE

    create_table_end

    create_html_end


阅读(882) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~