Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Convert Txt file to HTML table and email Post 302966020 by drl on Saturday 6th of February 2016 11:32:52 AM
Old 02-06-2016
Hi.

I have used utility t2t for years to solve such problems. Here's a demonstration:
Code:
#!/usr/bin/env bash

# @(#) s1       Demonstrate utility to produce HTML tables, t2t.
# http://www.scholnick.net/t2t

# Utility functions: print-as-echo, print-line-with-visual-space, debug.
# export PATH="/usr/local/bin:/usr/bin:/bin"
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe() { for _i;do printf "%s" "$_i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
db() { ( printf " db, ";for _i;do printf "%s" "$_i";done;printf "\n" ) >&2 ; }
db() { : ; }
C=$HOME/bin/context && [ -f $C ] && $C t2t

FILE=${1-data1}
SCR=f1

pl " Input data file $FILE:"
cat -A $FILE

# Change multiple spaces to TABs:
sed 's/   */\t/g' $FILE > $SCR
pl " Modified input file $SCR:"
cat -A $SCR

pl " Results, output file is ${SCR}.html:"
# Below is for single spaces as delimiters.
# t2t --delim " " --squeeze --header --overwrite $FILE
t2t --header --overwrite $SCR

exit 0

producing:
Code:
$ ./s1

Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution        : Debian 8.3 (jessie) 
bash GNU bash 4.3.30
t2t 7.3.1

-----
 Input data file data1:
Application Name      Application Status$
Application 1              Open$
Application 2              Open$
Application 3              Closed$
Application 4              Open$

-----
 Modified input file f1:
Application Name^IApplication Status$
Application 1^IOpen$
Application 2^IOpen$
Application 3^IClosed$
Application 4^IOpen$

-----
 Results, output file is f1.html, see attachment

The link for t2t is in the comments of the script.

Best wishes ... cheers, drl
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Format txt file as html table

I have a short time to solve a problem, so I need some help. I've searched the forum, but I couldn't find a solution to my problem. I made a script to filter some text and now I have a new requirement to make it available as html table. Problem is that I more than one files with different set... (2 Replies)
Discussion started by: tetreb
2 Replies

2. Shell Programming and Scripting

Is it possible to convert text file to html table using perl

Hi, I have a text file say file1 having data like ABC c:/hm/new1 Dir DEF d:/ner/d sd ...... So i want to make a table from this text file, is it possible to do it using perl. Thanks in advance Sarbjit (1 Reply)
Discussion started by: sarbjit
1 Replies

3. Shell Programming and Scripting

Convert shell script output txt file to html table

Hi, I have script which generates the output as below: Jobname Date Time Status abc 12/9/11 17:00 Completed xyz 13/9/11 21:00 Running I have the output as a text file. I need to convert it into a HTML Table and sent it thru email ... (6 Replies)
Discussion started by: a12ka4
6 Replies

4. UNIX and Linux Applications

Ssmtp -t < /path/to/the/message.txt (How to format message.txt for html email)

ssmtp has been running well under Kubuntu 12.04.1 for plain text messages. I would like to send html messages with ssmtp -t < /path/to/the/message.txt, but I cannot seem to get the message.txt file properly formatted. I have tried various charsets, Content-Transfer-Encoding, rearranging the... (0 Replies)
Discussion started by: Ronald B
0 Replies

5. Shell Programming and Scripting

Need to convert output.txt into html file

I have output.txt file generated through shell scripts which need convert in tabular format using html can you please help me output.txt Token State Date1 Date2 Description Name 34567 open 27/06/13 28/06/13 ... (5 Replies)
Discussion started by: vijay_rajni
5 Replies

6. Shell Programming and Scripting

SQL query output convert to HTML & send as email body

Hi , I have a sql query in the unix script ,whose output is shown below.I want to convert this output to HTML table format & send email from unix with this table as email body. p_id src_system amount 1 A 100 2 B 200 3 C ... (3 Replies)
Discussion started by: jagadeeshn04
3 Replies

7. Shell Programming and Scripting

HTML table in email body using C Shell

I am using Sun Solaris ver. 5.10 and trying to send an HTML table in email body using mail command in C shell script. I tried following commands:- #1 mail -m "MIME-Version: 1.0;Content-type:text/html;charset=UTF-8" receiver@mail.com < file.html #2 mail -m "Content-type: text/html;" -s "This... (4 Replies)
Discussion started by: jnrohit2k
4 Replies

8. Shell Programming and Scripting

Regarding guidance related to HTML table in email body

Hello All, I have a query here. I am sending an HTML table(which I am creating it by a call to REST API, in a LINUX box) and from there I have to send it into an email. So following are the poins on same: As data is not static so it is writing Dynamic data and creating HTML file. There is... (9 Replies)
Discussion started by: RavinderSingh13
9 Replies

9. Shell Programming and Scripting

Convert shell script output txt file to html table

My concnern related to the post -Convert shell script output txt file to html table, in this how to print the heading as color. awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' <filename> (8 Replies)
Discussion started by: sarajobmai
8 Replies

10. Shell Programming and Scripting

Postgre Query results as Email HTML table

Hello, I'm trying to send email from Greenplum query results as HTML table with status Red/Green Select Server, Last_Date from Table; Results Server, Last_Date Prod, 2018-04-09 Final email Output in HTML format Server Status LastDate Prod GREEN(BOX) 2018-04-09 (if... (2 Replies)
Discussion started by: krux_rap
2 Replies
TXT2TAGS(1)						      General Commands Manual						       TXT2TAGS(1)

NAME
txt2tags - text formatting and conversion tool SYNOPSIS
txt2tags [options] [FILE...] DESCRIPTION
txt2tags reads a text file with minimal markup and convert it to: ASCII Art, AsciiDoc, Creole, DocBook, DokuWiki, Google Code Wiki, HTML, LaTeX, Lout, MagicPoint, Man page, MoinMoin, PageMaker, Plain Text, PmWiki, SGML, Wikipedia and XHTML. This man page was created by txt2tags from a simple text file. The same text file is also converted to HTML for the online version of this manual. ONE source, MULTI targets - http://txt2tags.org MARKUP
Headers First 3 lines of the source file Title = words = Numbered title + words + Comment % comments Separator line -----------------------... Strong line =======================... Image [filename.jpg] Link [label url] Bold **words** Italic //words// Underline __words__ Strike --words-- Monospaced ``words`` Raw ""words"" Tagged ''words'' Paragraph words Quote <TAB>words List - words Numbered list + words Definition list : words Table | cell1 | cell2 | cell3... Verbatim line ``` words Raw line """ words Tagged line ''' words Verbatim block ``` lines ``` Raw block """ lines """ Tagged block ''' lines ''' OPTIONS
--art-chars=PATTERN Define PATTERN as the pattern of characters used to compose the ASCII Art decorations, in the following order: corner, border, side, bar1, bar2, level2, level3, level4, level5. The default pattern value is +-|-==-^". This option is only used by the ASCII Art tar- get. -C, --config-file=FILE Read configuration from the external file FILE. The configuration must be on the %!keyword:value format. See SETTINGS section for details. --css-sugar Improves the generated HTML/XHTML code to be used with CSS files. Tag attributes are removed, presentation tags are avoided, header is composed by H1, H2 and H3 tags, new DIVs are created: #header, #body, .toc. --css-inside Insert CSS file contents inside HTML/XHTML headers. Use --style to specify a CSS file to be read. --dump-config Print all the configuration found and exit. --dump-source Print the document source, with includes (%!include) expanded. --encoding=CODE Set the character set (file encoding) used by the source document to CODE. Examples are UTF-8 and iso-8859-1. --gui Invoke Graphical Tk Interface. -h, --help Print help information and exit. -H, --no-headers Suppress header and footer from the output. Only the contents (body) will be shown. --headers Show header and footer in the output. Default is ON. --height=NUM Set the output's height to NUM rows. This option is only used by the ASCII Art target, when also using --slides. -i, --infile=FILE Set FILE as the input file name, the source document. Use '-' to read the sources from the STDIN. --mask-email Hide emails from spam robots. Removes @ and dots. The address foo@bar.com turns to <foo (a) bar com>. -n, --enum-title Turn on automatic numbering for titles. They will be prefixed by 1, 1.1, 1.1.1, ... --no-dump-config Cancel the --dump-config action. --no-dump-source Cancel the --dump-source action. --no-encoding Clear the encoding setting. --no-enum-title Turn off the automatic numbering for titles. --no-infile Clear all the previous infile declarations. --no-targets Cancel the --targets action. --no-mask-email Turn off the email masking feature. --no-outfile Clear the previous outfile declaration. --no-quiet Show messages, turning off the --quiet option. --no-rc Do not read the user configuration file ~/.txt2tagsrc. --no-slides Turn off the slides feature. --no-style Clear all the style settings. --no-toc Remove the Table of Contents from the output. --no-toc-only Turn off the --toc-only action. -o, --outfile=FILE Set FILE as the output file name. Use '-' to send the results to STDOUT. -q, --quiet Quiet mode. Suppress all output, except errors. --rc Read the user configuration file ~/.txt2tagsrc. Default is ON. --slides Format output as presentation slides. This option is only used by the ASCII Art target. --style=FILE Use FILE as the document's style file. Used to define CSS files for HTML/XHTML documents and packages for LaTeX. This option can be used multiple times to include multiple files. -t, --target=TYPE Set the output document format to TYPE. Some popular types are: html, xhtml, tex, man, txt. Use the --targets option to see all the available formats. --targets Print a list of all the available targets and exit. --toc Include an automatic Table of Contents (TOC) to the output, between the Header and the Body. You can also specify the TOC position using the %%TOC macro. --toc-level=NUM Set the maximum TOC level to NUM. All titles deeper than NUM will not be included in the Table of Contents. --toc-only Print the Table of Contents and exit. -v, --verbose Print informative messages during conversion. This option can be used multiple times to increase the number of messages shown. -V, --version Print program version and exit. --width=NUM Set the output's width to NUM columns. This option is only used by the ASCII Art target. SOURCE FILES
The source files are usually identified by the .t2t extension (such as myfile.t2t). You may have three areas inside your sources: Header (optional) The first three lines of the file. Leave the first line blank if you don't need headers. Used for document title, author, version and date information. Settings (optional) Begins right after the Header (4th or 2nd line) and ends when the Body area starts. Used for settings (configurations) in the %!keyword:value format. Body Begins at the first valid text line (not comment or setting) after the Header area and goes until the end of the document. Used for the document contents. SETTINGS
Settings let you customize txt2tags, they're similar to options. They can be used at: source document's Settings area, ~/.txt2tagsrc file, external file called with --config-file. %!target Set the output format, just like --target. Example: %!target: html %!options(target) Set the default options to each target. You must use the command line options. Example: %!options(html): --toc --toc-level 3 --css-sugar %!includeconf Include configurations from an external file into the current, just like --config-file. Example: %!includeconf: myconfig.t2t %!style Set a style file for the document, just like --style. Can be used multiple times. Example: %!style: colors.css %!encoding Set the character set used by the document, just like --encoding. Example: %!encoding: UTF-8 %!preproc Input search/replace filter used to change the Body of the source document BEFORE any parsing by txt2tags. Search uses Python regu- lar expressions. Example: %!preproc: "JJS" "John J. Smith" %!postproc Output search/replace filter used to change the generated document AFTER all the txt2tags processing. Search uses Python regular expressions. Example: %!postproc(html): "<B>" "<STRONG>" If the same keyword appears more than once, the last found will be the one used (except: options, preproc and postproc, which are cumula- tive). Invalid keywords are ignored. The parsing order is: ~/.txt2tagsrc, source document's Config area, --config-file option. COMMANDS
Commands perform tasks during conversion time. They must be placed at the source document's Body. %!csv: file.csv Includes an external CSV file as a table. %!include: file.t2t Includes a txt2tags file in the document. %!include: ``file.txt`` Includes a text file (verbatim) in the document. %!include: ''file.html'' Includes an already tagged file in the document. MACROS
Macros are handy shortcuts to insert dynamic contents in your document. They must be placed at the source document's Body. Except %%toc, all macros can be customized with special directives, like %Y and %f. See the txt2tags User Guide for details. %%date Insert the current date. The default format is %%date(%Y%m%d), which gives YYYYMMDD. %%infile Insert the source file path. The default format is %%infile(%f). Useful for footer links like [See source %%infile]. %%mtime Insert the source file modification time. The default format is %%date(%Y%m%d), which gives YYYYMMDD. %%outfile Insert the output file path. The default format is %%outfile(%f). Useful for self mentioning like "This is the manpage.man file". %%toc Specifies where the Table of Contents will be placed. You can even use it multiple times. Note that you must also use the --toc option. EXAMPLES
txt2tags -t html file.t2t Convert to HTML, saving to file.html. txt2tags -t html -o - file.t2t Convert to HTML, sending results to STDOUT. txt2tags -t html --toc file.t2t Convert to HTML, including automatic Table Of Contents. txt2tags -t html --toc --toc-level 2 -n file.t2t Convert to HTML, with a two level Table of Contents and numbered titles. txt2tags --toc-only file.t2t Just show the Table of Contents, no conversion is done. txt2tags -t html --css-sugar --style base.css --style ui.css file.t2t Convert to HTML, preparing the resulting code to be used with CSS, and also include calls to two external CSS files. txt2tags -t art --slides --width 80 --height 25 -o - file.t2t | more Create ASCII Art presentation slides, ready to be shown in a 80x25 terminal screen/window. (echo ; echo "**bold**") | txt2tags -t html -H - Handy one-liner for quick tests using STDIN. txt2tags -t html -o - file.t2t | tidy > file.html Send results to STDOUT, then fine tune the code with an external program before saving the output file. FILES
~/.txt2tagsrc Default user configuration file. ENVIRONMENT
T2TCONFIG If non-null, sets the full pathname for the default user configuration file. AUTHOR
Aurelio Jargas <verde@aurelio.net> BUGS
http://bugs.txt2tags.org COPYRIGHT
Copyright (C) 2001-2010 Aurelio Jargas, GNU GPL v2 Aug, 2010 TXT2TAGS(1)
All times are GMT -4. The time now is 08:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy