最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

linux shell txt轉(zhuǎn)換成html的實(shí)現(xiàn)代碼

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

原理: awk命令,分割格式化的txt(txt文件格式以“|”分割開的)成數(shù)組,然后拼接成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

測(cè)試的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 實(shí)現(xiàn)txt轉(zhuǎn)換成html(源碼下載)

相關(guān)文章

  • Linux常用ls, alias基礎(chǔ)命令詳解

    Linux常用ls, alias基礎(chǔ)命令詳解

    這篇文章主要介紹了Linux常用ls, alias基礎(chǔ)命令詳解,ls命令 的作用是列舉目錄文件信息,alias查看定義的別名,具體內(nèi)容詳情大家參考下本文
    2018-05-05
  • shell腳本中整數(shù)型變量自增(加1)的幾種實(shí)現(xiàn)

    shell腳本中整數(shù)型變量自增(加1)的幾種實(shí)現(xiàn)

    本文主要介紹了shell腳本中整數(shù)型變量自增(加1)的幾種實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-05-05
  • Linux命令行里的“瑞士軍刀”

    Linux命令行里的“瑞士軍刀”

    本文說的瑞士軍刀是指那些簡(jiǎn)單的一句命令就能完成其它高級(jí)語言一大片代碼才能完成的工作
    2013-07-07
  • 詳解linux下tree命令的用法

    詳解linux下tree命令的用法

    tree是一種遞歸目錄列表命令,產(chǎn)生一個(gè)深度縮進(jìn)列表文件,這是彩色的ALA dircolors如果ls_colors設(shè)置環(huán)境變量和輸出是TTY。下面通過本文給大家分享linux下tree命令的用法,感興趣的朋友一起看看吧
    2017-09-09
  • shell腳本連接并重啟遠(yuǎn)程服務(wù)器的方法

    shell腳本連接并重啟遠(yuǎn)程服務(wù)器的方法

    這篇文章主要介紹了shell腳本連接并重啟遠(yuǎn)程服務(wù)器方法,需要的朋友可以參考下
    2017-03-03
  • Bash中數(shù)組的操作教程

    Bash中數(shù)組的操作教程

    這篇文章主要介紹了Bash數(shù)組操,包括定義數(shù)組、讀取數(shù)組、修改數(shù)組以及數(shù)組循環(huán),文中通過示例代碼給出了詳細(xì)的介紹,有需要的朋友可以參考下,下面來一起看看吧。
    2016-12-12
  • linux查看nginx安裝路徑的方法

    linux查看nginx安裝路徑的方法

    這篇文章主要介紹了linux查看nginx安裝路徑的方法,文中有相關(guān)的代碼示例供大家參考,具有很好的參考價(jià)值,對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下
    2023-11-11
  • Linux下is not in the sudoers file的解決方案

    Linux下is not in the sudoers file的解決

    當(dāng)我們使用sudo命令切換用戶的時(shí)候可能會(huì)遇到提示以下錯(cuò)誤:用戶名 is not in the sudoers file.本文給大家分享原因分析及解決方案,感興趣的朋友跟隨小編一起看看吧
    2023-02-02
  • 如何使用 Bash 腳本中的time命令來統(tǒng)計(jì)命令執(zhí)行時(shí)間(中英雙語)

    如何使用 Bash 腳本中的time命令來統(tǒng)計(jì)命令執(zhí)行時(shí)間(中英雙語)

    本文介紹了如何在Bash腳本中使用`time`命令來測(cè)量命令執(zhí)行時(shí)間,包括`real`、`user`和`sys`三個(gè)時(shí)間指標(biāo),并展示了如何格式化輸出和將結(jié)果保存到文件中,感興趣的朋友一起看看吧
    2025-01-01
  • 淺析Linux tar打包命令

    淺析Linux tar打包命令

    這篇文章主要介紹了Linux tar打包命令,本文給大家?guī)戆藗€(gè)范例,每個(gè)范例都給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-06-06

最新評(píng)論

龙泉市| 黑山县| 浦江县| 凤城市| 东明县| 丰台区| 九江县| 隆尧县| 吉安市| 南开区| 邹城市| 九龙县| 石景山区| 错那县| 汤原县| 上栗县| 达州市| 河东区| 沭阳县| 余江县| 广东省| 凤冈县| 新竹县| 游戏| 泗洪县| 永兴县| 简阳市| 林芝县| 时尚| 乌兰浩特市| 民权县| 邛崃市| 沅江市| 古丈县| 铅山县| 惠来县| 即墨市| 七台河市| 吉林省| 阜平县| 永仁县|