欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2016年11月21日 23:51:36   投稿:mdxy-dxy  
這篇文章主要介紹了linux shell txt轉換成html的實現代碼,需要的朋友可以參考下

原理: 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(源碼下載)

相關文章

  • Linux下模擬實現進度條實例詳解

    Linux下模擬實現進度條實例詳解

    這篇文章主要介紹了Linux下模擬實現進度條實例詳解的相關資料,需要的朋友可以參考下
    2017-06-06
  • 把mysql查詢結果保存到文件的shell腳本

    把mysql查詢結果保存到文件的shell腳本

    這篇文章主要介紹了把mysql查詢結果保存到文件的shell腳本,使用mysql的SELECT INTO OUTFILE備份語句,需要的朋友可以參考下
    2014-03-03
  • Linux traceroute命令使用方法實例詳解

    Linux traceroute命令使用方法實例詳解

    這篇文章主要介紹了Linux traceroute命令使用方法實例詳解的相關資料,希望通過本文能幫助到大家,讓大家理解應用這部分內容, 需要的朋友可以參考下
    2017-10-10
  • Linux下shell通用腳本啟動jar(微服務)

    Linux下shell通用腳本啟動jar(微服務)

    這篇文章主要介紹了Linux下shell通用腳本啟動jar(微服務)的方法,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-10-10
  • Shell退出狀態(tài)的使用

    Shell退出狀態(tài)的使用

    這篇文章主要介紹了Shell退出狀態(tài)的使用,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • linux下socket編程常用頭文件(推薦)

    linux下socket編程常用頭文件(推薦)

    這篇文章主要介紹了linux下socket編程常用頭文件,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-10-10
  • linux sudo密碼輸入時顯示星號的操作方法

    linux sudo密碼輸入時顯示星號的操作方法

    在輸入linux sudo密碼的時候終端是不顯示任何東西的,我們不知道我們按下的密碼到底輸入進去了沒有,如果可以像在網站上登錄賬號密碼的時候顯示星號多好,下面小編給大家介紹下linux sudo密碼輸入時顯示星號的操作方法
    2018-01-01
  • Linux下.tar.xz文件的解壓教程詳解

    Linux下.tar.xz文件的解壓教程詳解

    xz這個壓縮可能很多都很陌生,不過您可知道xz是絕大數linux默認就帶的一個壓縮工具。接下來通過本文給大家分享Linux下.tar.xz文件的解壓教程詳解,需要的朋友參考下吧
    2017-10-10
  • 執(zhí)行Shell腳本的4種方法及區(qū)別介紹

    執(zhí)行Shell腳本的4種方法及區(qū)別介紹

    這篇文章主要介紹了執(zhí)行Shell腳本的4種方法及區(qū)別介紹,本文講解了相對路徑方式、絕對路徑方式、bash命令調用、相對或絕對方式以及說下幾種方式的區(qū)別,需要的朋友可以參考下
    2015-05-05
  • 如何使用shell獲取進程名的內存以及CPU利用率

    如何使用shell獲取進程名的內存以及CPU利用率

    最近工作中遇到一個需求,需要找出占用高的進程,所以下面這篇文章主要給大家介紹了關于如何使用shell獲取進程名的內存以及CPU利用率的相關資料,需要的朋友可以參考下
    2022-04-04

最新評論