婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > linux shell txt轉換成html的實現代碼

linux shell txt轉換成html的實現代碼

熱門標簽:鶴崗400電話申請 百度地圖標注直線距離 天津電話外呼系統排名 外呼電話系統怎么操作 智能電銷機器人有用嗎 測繪地圖標注名稱 怎么在百度地圖標注公司的位置 商機地圖標注 德陽400電話申請

原理: awk命令,分割格式化的txt(txt文件格式以“|”分割開的)成數組,然后拼接成html格式(html - head - title - body - table)

shell源碼

# !/bin/sh

file_input='txt.log'
file_output='txt2html.html'

td_str=''

function create_html_head(){
  echo -e "html>
    body>
      h1>$file_input/h1>"
}

function create_table_head(){
  echo -e "table border="1">"
}

function create_td(){
#  if [ -e ./"$1" ]; then
    echo $1
    td_str=`echo $1 | awk 'BEGIN{FS="|"}''{i=1; while(i=NF) {print "td>"$i"/td>";i++}}'`
    echo $td_str
#  fi
}

function create_tr(){
  create_td "$1"
  echo -e "tr>
    $td_str
  /tr>" >> $file_output
}

function create_table_end(){
  echo -e "/table>"
}

function create_html_end(){
  echo -e "/body>/html>"
}


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

測試的txt格式:

Angry Birds|Arcade  Action|4.6|887,058|10,000,000 - 50,000,000|Free|August 30, 2011|1.6.3|19M|1.6 and up|Low Maturity
Angry Birds Seasons|Arcade  Action|4.5|314,060|10,000,000 - 50,000,000|Free|September 1, 2011|1.6.0|22M|1.6 and up|Low Maturity
Bunny Shooter Free Game|Brain  Puzzle|4.9|121,579|1,000,000 - 5,000,000|Free|September 7, 2011|1.06|8.6M|2.1 and up|Low Maturity
Angry Birds Rio|Arcade  Action|4.7|310,324|10,000,000 - 50,000,000|Free|August 29, 2011|1.3.0|17M|1.6 and up|Everyone
Words With Friends Free|Brain  Puzzle|3.7|312,017|10,000,000 - 50,000,000|Free|September 1, 2011|Varies with device|Varies with device|2.1 and up|Everyone
TETRIS® free|Brain  Puzzle|3.8|1,288|500,000 - 1,000,000|Free|September 1, 2011|1.0.27|8.7M|1.6 and up|Low Maturity
Drag Racing|Racing|4.5|150,279|10,000,000 - 50,000,000|Free|September 9, 2011|1.1.3|6.5M|1.6 and up|Everyone
Drunk Man|Racing|3.6|2,388|1,000,000 - 5,000,000|Free|September 2, 2011|1.2.1|998k|1.5 and up|Everyone
Solitaire|Cards  Casino|4.3|83,548|10,000,000 - 50,000,000|Free|December 22, 2010|1.12.2|83k|1.0 and up|Everyone
Dragon, Fly!|Arcade  Action|4.6|46,790|1,000,000 - 5,000,000|Free|September 3, 2011|1.8|3.2M|1.6 and up|Low Maturity
Pimple Popper|Arcade  Action|2.7|3,014|1,000,000 - 5,000,000|Free|September 8, 2011|1.8|2.2M|2.0 and up|Low Maturity
Fruit Ninja Free|Arcade  Action|4.5|13,915|1,000,000 - 5,000,000|Free|August 4, 2011|1.6.2.10|18M|2.1 and up|Low Maturity
Fruit Slice|Arcade  Action|4.5|165,603|10,000,000 - 50,000,000|Free|September 14, 2011|1.3.2|4.0M|1.6 and up|Everyone
Prize Claw|Arcade  Action|3.9|1,102|500,000 - 1,000,000|Free|September 2, 2011|1.1|13M|2.0.1 and up|Everyone
3D Bowling|Arcade  Action|4.0|14,794|5,000,000 - 10,000,000|Free|June 28, 2011|1.3|9.8M|2.0.1 and up|Everyone
7 Little Words|Brain  Puzzle|4.8|21,073|500,000 - 1,000,000|Free|August 10, 2011|1.00|3.2M|2.2 and up|Everyone
Third Blade|Arcade  Action|4.3|6,475|500,000 - 1,000,000|Free|September 9, 2011|1.0.2|49M|1.6 and up|Medium Maturity
Shoot Bubble Deluxe|Arcade  Action|4.2|11,645|5,000,000 - 10,000,000|Free|May 28, 2011|2.5|1.1M|1.1 and up|Everyone
Racing Moto|Arcade  Action|4.4|79,829|1,000,000 - 5,000,000|Free|August 20, 2011|1.1.2|3.9M|1.6 and up|Everyone
Zynga Poker|Cards  Casino|4.6|91,976|1,000,000 - 5,000,000|Free|August 31, 2011|Varies with device|Varies with device|2.0.1 and up|Medium Maturity

生成的html:

shell 實現txt轉換成html(源碼下載)

您可能感興趣的文章:
  • 一天一個shell命令 linux文本操作系列-tree命令詳解
  • Linux shell 之 提取文件名和目錄名的一些方法總結
  • Linux shell常用的73條命令總結
  • Linux下使用shell腳本自動執行腳本文件
  • linux下執行shell命令方法簡介
  • linux寫shell需要注意的問題(必看)
  • Linux Shell腳本的編程之正則表達式
  • linux shell 路徑截取正則表達式
  • Linux shell實現HTTP服務示例代碼
  • Linux shell tr 命令詳解

標簽:丹東 六盤水 自貢 滁州 武漢 優質小號 百色 鎮江

巨人網絡通訊聲明:本文標題《linux shell txt轉換成html的實現代碼》,本文關鍵詞  linux,shell,txt,轉,換成,html,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《linux shell txt轉換成html的實現代碼》相關的同類信息!
  • 本頁收集關于linux shell txt轉換成html的實現代碼的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 甘谷县| 定结县| 松潘县| 双城市| 阿尔山市| 博客| 休宁县| 枣庄市| 西丰县| 巴彦淖尔市| 斗六市| 吉林省| 桓仁| 东乡县| 左云县| 宁蒗| 安义县| 海晏县| 将乐县| 大连市| 漯河市| 丘北县| 东阳市| 鹿邑县| 河源市| 凭祥市| 庄浪县| 壤塘县| 个旧市| 高密市| 湘乡市| 弋阳县| 新乡市| 南投市| 绥德县| 化德县| 连州市| 西乌珠穆沁旗| 西畴县| 沾化县| 石家庄市|