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

shell源码

# !/bin/shfile_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" ]; thenecho $1td_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_outputtouch $file_outputcreate_html_head >> $file_outputcreate_table_head >> $file_outputwhile read linedoecho $linecreate_tr "$line" done < $file_inputcreate_table_end >> $file_outputcreate_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(源码下载)

转载于:https://www.cnblogs.com/springside4/archive/2011/09/15/2481619.html

shell 实现txt转换成html相关推荐

  1. 将文字或txt转换成GBK或者UTF8编码

    将文字或txt转换成GBK或者UTF8编码 用到的工具 Sublime Text 3 点击下载 安装好后 打开界面输入ctrl+shift+p键 界面弹出输入框 输入install package 回 ...

  2. python 文本转excel_Python 文本(txt) 转换成 EXCEL(xls)

    #!/bin/env python # -*- encoding: utf-8 -*- #------------------------------------------------------- ...

  3. 如何将txt转换成pdf格式

    随手记录文字最方便的文档格式要数txt了,要记录文字大家想必都会用它,没错,txt用来记录一些文字是非常方便,但是它不安全啊,而且不是一种正式的格式,所以在工作中我们还是需要把它转换成其他格式,比如p ...

  4. python读取一个TXT转换成EXCEL表格

    [任务]:python读取一个TXT转换成EXCEL表格 [坑1]pycharm安装后代码区不能编辑,是由于最新的pycharm在安装时自动装了vimVim插件, 方法一:在tools-Vim emu ...

  5. TXT转换成pdf出现乱码怎么办

    不少上班族疑惑不定,为什么自己使用的 txt转换成pdf转换器把TXT转换成PDF文档后,生成的PDF文档里面的文字全是乱码,仅有部分的段落是正常的,而大多数的文字和表格却都是错乱的?这到底是怎么回事 ...

  6. 教你怎么把txt转换成pdf格式

    早前从"糯米TXT论坛"网上发现了一部科幻恐怖小说,细细品读了里面的内容觉得还不错,于是将它拷贝下来放在自己的桌面上以备休闲时读,这不趁着吃中饭这空挡,我随手就打开了TXT格式文件 ...

  7. 将txt转换成pdf格式的转换方法分享

    因为喜欢看小说所以发现不少网上电子书现在下载的版本都是TXT格式的,TXT虽然在修改文字上确实方面,可是如果谈及到阅读效果,实在不敢恭维.记得曾经在网上看到一部武侠小说本想下载下来,打算空闲时候看看, ...

  8. 将txt转换成pdf格式的操作方法

    一般办公或是学习过程中,我们将一些有用的文字资料保存在Word.TXT等文档中,而有时需要将已经编辑.打印好的材料,做成PDF格式的电子书,以供我们日后查阅使用.如果在两者之间通过一块块地复制.粘贴. ...

  9. 将txt转换成pdf格式的详细步骤

    现在网上很多小说.书籍都是TXT格式的,不少朋友想把它转换成高质量的PDF文件格式,然后在支持PDF的设备上读取和阅读.如果电脑上安装专业的TXT转PDF便捷工具,那么将TXT文本转换成PDF文档就是 ...

最新文章

  1. 多项式加法c语言数组解,急!!!!c语言:求n次多项式的加法和乘法
  2. hadoop中datanode无法启动,报Caused by: java.net.NoRouteToHostException: No route to host
  3. ad09只在一定范围内查找相似对象_23、面向对象编程
  4. 引路蜂地图API:Gis.Navigation包定义
  5. php 共享内存列队,php中对共享内存,消息队列的操作
  6. HDU1290 献给杭电五十周年校庆的礼物【水题】
  7. 转换到coff期间_Visual Studio转换到coff期间失败该怎么解决?
  8. 判断是否是anagram
  9. 微服务守护神-Sentinel-降级规则
  10. <C++>初识多态,剖析virtual关键字
  11. 如何管理一个外包团队小总结
  12. 后端使用thymeleaf模板生成页面转pdf,结果客户现场中文不显示
  13. 史上最佳十大游戏排名 魔兽世界位列第十
  14. RRT(Rapidly-Exploring Random Trees)算法详解及python实现
  15. 3D和IMAX 3D带你体验加勒比的惊涛怪浪
  16. Mongodb 源码分析:整体架构
  17. 洛谷P2495 [SDOI2011]消耗战 | 一个典型的可以搞懂虚树的例题
  18. 【渝粤教育】电大中专计算机应用基础 (2)_1作业 题库
  19. 第二篇:java调用公共数据接口:上海市车辆基本信息查询(java调用soap接口)
  20. 常用的post、get工具说明

热门文章

  1. php 操件文件指定编码,(PHP帮助)如果文件中存在特定编号,请执行此操作
  2. php修改ip6地址为ip4,CentOS7 设置静态IPv6/IPv4地址
  3. 关于scanf对换行的吸收
  4. PSIM软件学习---06 元件参数文件应用
  5. Nginx——安装详解
  6. 一文搞懂隐马尔可夫模型(HMM)
  7. IntelliJ Idea中使用Java8新特性lambda表达式
  8. 我是如何解决jobtracker.info could only be replicated to 0 nodes, instead of 1这个问题的
  9. Pytorch:函数的手动梯度计算方法
  10. struts html:radio标签的初始值与判断