Shell脚本CSV2HTML表格

网上看了一个不错的脚本,改了一点点,记录一下,

 

 
 
  1. #!/bin/sh 
  2. CSVFILE= 
  3. while getopts c: opt 
  4. do 
  5.         case $opt in 
  6.                 c) CSVFILE=$OPTARG 
  7.                 ;; 
  8.                 '?') echo "Usage: -c csv file name" 
  9.                 ;; 
  10.         esac 
  11. done 
  12.  
  13. TD_STR="" 
  14.  
  15. #this function create a <td> block 
  16. create_td() 
  17.   #echo $1 
  18.   TD_STR=`echo $1 | awk 'BEGIN{FS=","}{i=1; while(i<=NF) {print "<td>"$i"</td>";i++}}'
  19. #this function create a row html script(<tr>block). 
  20. create_tr() 
  21.   create_td "$1" 
  22.   echo -e "<tr>\n$TD_STR\n<tr/>\n" 
  23. #create html script head 
  24. create_html_head() 
  25.   echo -e "<html>\n<body>\n<h1>$CSVFILE</h1>\n" 
  26. #create html script end 
  27. create_html_end() 
  28.   echo '</body></html>' 
  29. create_table_head() 
  30.   echo -e "<table border="1">\n" 
  31. create_table_end() 
  32.    echo -e "</table>\n" 
  33. create_html_head 
  34. create_table_head 
  35. while read LINE 
  36. do 
  37.  # echo "$LINE" 
  38.   create_tr "$LINE" 
  39. done < $CSVFILE 
  40. create_table_end 
  41. create_html_end 

 

本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1128227,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值