Shell converts TXT to HTML

Source: Internet
Author: User

Principle: awk command, split formatted txt (txt file format separated by "|") into an array, and then splice it into HTML format (HTML-head-title-body-table)

Shell Source Code

<PRE name = "code" class = "Python"> #! /Bin/shfile_input0000'txt.log'file_output0000'txt2html.html 'TD _ STR = ''function create_html_head () {echo-e "<HTML> <body> <p> $ file_input </p>"} 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> </ptml>"} 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 </PRE> <p>
TXT format for testing:

Angry Birds | arcade & Action | 4.6 | 887,058 | 10,000,000-50,000,000 | free | August 30,201 1 | 1.6.3 | 19m | 1.6 and up | low maturity <br/> 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 <br/> 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 <br/> angry bi RDS Rio | arcade & Action | 4.7 | 310,324 | 10,000,000-50,000,000 | free | August 29,201 1 | 1.3.0 | 17m | 1.6 and up | everyone <br/> Words With Friends free | brain & puzzle | 3.7 | 312,017 | 10,000,000-50,000,000 | free | September 1, 2011 | varies with device | 2.1 and up | everyone <br/> 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 <br/> Dr Ag 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 <br/> 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 <br/> solitaire | Cards & Casino | 4.3 | 83,548 | 10,000,000-50,000,000 | free | December 22,201 0 | 1.12.2 | 83k | 1.0 and up | everyone <br/> 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 <br/> 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 <br/> 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 <br/> fruit slice | arcade & Action | 4.5 | 165,603 | 10,000,000-50,000,000 | free | September 14,201 1 | 1.3.2 | 4.0m | 1.6 and up | everyone <br/> 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 <br/> 3D bowling | arcade & Action | 4.0 | 14,794 | 5,000,000-10,000,000 | free | June 28,201 1 | 1.3 | 9.8m | 2.0.1 and up | everyone <br/> 7 little words | brain & puzzle | 4.8 | 21,073 | 500,000-1,000,000 | free | August 10,201 1 | 1.00 | 3.2m | 2.2 and up | everyone <br/> 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 <br/> shoot bubble deluxe | arcade & Action | 4.2 | 11,645 | 5,000,000-10,000,000 | free | May 28,201 1 | 2.5 | 1.1m | 1.1 and up | everyone <br/> racing Moto | arcade & Action | 4.4 | 79,829 | 1,000,000-5,000,000 | free | August 20,201 1 | 1.1.2 | 3.9m | 1.6 and up | everyone <br/> Zynga poker | Cards & Casino | 4.6 | 91,976 | 1,000,000-5,000,000 | free | August 31,201 1 | varies with device | 2.0.1 and up | Medium Maturity

Generated HTML:

Shell converts TXT files to HTML (source code download)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.