网上看了一个不错的脚本,改了一点点,记录一下,
- #!/bin/sh
- CSVFILE=
- while getopts c: opt
- do
- case $opt in
- c) CSVFILE=$OPTARG
- ;;
- '?') echo "Usage: -c csv file name"
- ;;
- esac
- done
- TD_STR=""
- #this function create a <td> block
- create_td()
- {
- #echo $1
- TD_STR=`echo $1 | awk 'BEGIN{FS=","}{i=1; while(i<=NF) {print "<td>"$i"</td>";i++}}'`
- }
- #this function create a row html script(<tr>block).
- create_tr()
- {
- create_td "$1"
- echo -e "<tr>\n$TD_STR\n<tr/>\n"
- }
- #create html script head
- create_html_head()
- {
- echo -e "<html>\n<body>\n<h1>$CSVFILE</h1>\n"
- }
- #create html script end
- create_html_end()
- {
- echo '</body></html>'
- }
- create_table_head()
- {
- echo -e "<table border="1">\n"
- }
- create_table_end()
- {
- echo -e "</table>\n"
- }
- create_html_head
- create_table_head
- while read LINE
- do
- # echo "$LINE"
- create_tr "$LINE"
- done < $CSVFILE
- create_table_end
- create_html_end
本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1128227,如需转载请自行联系原作者