Required to get out put of log in tabular format in email body

Dears Please support

I have out put in text file and look like below

fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action hhttp://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action http://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app

This is one column
fixed inquiries - Click on MAX suffix
This is other column http://server:port/app

I used below command to take output in different html format and it is giving me tabular format but how can i put color because it is white background.which place and how i should update color

nawk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' ERROR_FILE.log > ERROR_FILE.xls

fixed inquiries - Click on MAX suffix
and i want script to consider above in one column
like before http it should be in one column and later should be in other

please support to help me add color and also help me make my output come in two columns

Show the input you have and the output you want.

in put in file look like this and there can b n number of rows

fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action hhttp://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action http://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app

output i want is like below
fixed inquiries - Click on MAX suffix in one column in table
and this is other column http://server:port/app

and i want to print out put in email body in a tabular form.

Thanks in advance

---------- Post updated at 10:08 PM ---------- Previous update was at 09:41 PM ----------

in put in file look like this and there can b n number of rows

fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action hhttp://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action http://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app

output i want is like below
fixed inquiries - Click on MAX suffix in one column in table
and this is other column http://server:port/app

and i want to print out put in email body in a tabular form.

Thanks in advance

---------- Post updated at 10:34 PM ---------- Previous update was at 10:08 PM ----------

awaiting your feedback on this please

Awaiting your answer to Corona688's questions.

And, don't repeat your post#1 for the fourth time. Show the output and the logic/rules/algorithms that connect it with your input.

Dear Rudic,
i already provide my input file

fixed inquiries - Click on MAX suffix http://server: port/app
User Details  http://server: port/app
Audit User Detail Action http://server: port/app
fixed inquiries - Click on MAX suffix http://server: port/app
User Details  http://server: port/app
Audit User Detail Action http://server: port/app
fixed inquiries - Click on MAX suffix http://server: port/app

and i want out in tabular form in two coloms, with some color
one column before http and other with https till app.
out put required like below

fixed inquiries - Click on MAX suffix | http://server: port/app
Audit User Detail Action | http://server: port/app

---------- Post updated at 11:04 PM ---------- Previous update was at 10:44 PM ----------

Dear,

is the input requirement clear now, or do i need to provide more info on this ?

please help

Dear Mirwasim,
You posted the input several times. But the output Corona and Rudy want to see is not so clear. Based on your script I guess you want this output:

<TABLE>
  <TR>
    <TD>fixed inquiries - Click on MAX suffix</TD>
    <TD>http://server: port/app</TD>
  </TR>
  ...
</TABLE>

That is enough for one question.
But you are also telling you want to mail this. Do you understand you will have to add HTML tags and perhaps more?
To mail this as a html you will have to set a mime type. That would be an other question.
Hope this helps.

I am very sorry if i am not able to explain my question clearly

i have every thing in place..
on my normal txt file i am running below command to generate html tags

nawk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' ERROR_FILE.log > ERROR_FILE.xls

this HTML is file is sent to email as well but table is not formed.
instead of having two column or multiple column I am okay to get each l column.

like for my input script i have 7 rows and these 7 rows should come in a tabular form.

As Ivo Breeden and others have already said, having a .txt file that contains some HTML tags, does not make that text file an HTML file. There is no <HTML> tag at the start of your file. There is no </HTML> tag at the end of your file. It is not a .html file. And, including a few HTML tags in a text file in a mail message will not cause that mail message to be fed through an HTML interpreter before being displayed by the mail reader of the user reading your mail message.

You have to encapsulate HTML code in a MIME type that will be interpreted by the mail reader whoever is reading your message will use to render those HTML tags as HTML code. How you do that depends on what you are using to send mail, what operating system you're using, and probably several other things you haven't bothered telling us.

Dear Don

Thanks for your time and response
I think I understood what is missing In my script
I have to add tags in the script and it should be fine
I Wil get back to you definitely with my results and also in case I have any doubt
Thanks

---------- Post updated at 01:05 PM ---------- Previous update was at 08:43 AM ----------

Dear Don,

I have managed to get the html output in email with tabular format.
I used below script

echo "<html>" >> ERROR_FILE.html
echo "<Body>" >> ERROR_FILE.html
nawk 'BEGIN{print "<table border="1">"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' ERROR_FILE.log >> ERROR_FILE.html
echo "</Body>" >> ERROR_FILE.html
echo "</html>" >> ERROR_FILE.html

But I have a little problem. I am getting each field in a different colum like below

fixed|inquiries| - |Click |on| MAX| suffix |http://server:port/app|

But I want output like below

fixed inquiries - Click on MAX suffix |  http://server:port/app

or the whole row in one column. now I am not sure what change to make in above highlighted nawk

fixed inquiries - Click on MAX suffix http://server:port/app

Thanks in advance

Hello Mirwasim,
Your script is getting better.
Try this:

nawk 'BEGIN{print "<table border="1">"}
       {print "<tr>";
       print "<TD>";
       for(i=1;i<NF;i++) printf("%s ",  $i);
       print "</TD>";
       print "<TD>" $NF "</TD>";
       print "</tr>"}
     END{print "</table>"}' ERROR_FILE.log

This results in:

<table border=1>
<tr>
<TD>
fixed inquiries - Click on MAX suffix </TD>
<TD>http://server:port/app</TD>
</tr>
<tr>
<TD>
User Details </TD>
<TD>http://server:port/app</TD>
</tr>
...

I hope this is what you need.

1 Like

Hi.

I like to use extant codes. Here is a demonstration of t2t , automatic creation of HTML tables, and hlins to insert URLs:

#!/usr/bin/env bash

# @(#) s1       Demonstrate automatic HTML table generation, t2t, hlins.
# t2t source:
# 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 hlins

FILE=${1-data1}

pl " Input data file $FILE:"
head $FILE

pl " Convert <space>http to <tab>http:"
sed 's/ http/   http/' $FILE |
tee f1

pl " Display name = URL database for hlins:"
head my-db

rm -f f1.html
pl " Results, create f1.html, f2.html:"
t2t f1

hlins -db my-db f1.html >f2.html

exit 0

producing

$ ./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.4 (jessie) 
bash GNU bash 4.3.30
t2t 7.3.1
Hlins v0.39

-----
 Input data file data1:
fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action http://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app
User Details  http://server:port/app
Audit User Detail Action http://server:port/app
fixed inquiries - Click on MAX suffix http://server:port/app
Other stuff     drl

-----
 Convert <space>http to <tab>http:
fixed inquiries - Click on MAX suffix   http://server:port/app
User Details    http://server:port/app
Audit User Detail Action        http://server:port/app
fixed inquiries - Click on MAX suffix   http://server:port/app
User Details    http://server:port/app
Audit User Detail Action        http://server:port/app
fixed inquiries - Click on MAX suffix   http://server:port/app
Other stuff     drl

-----
 Display name = URL database for hlins:
# Donald Knuth        =  http://www-cs-staff.stanford.edu/...
# http://server:port/app = http://server:port/app
drl = ftp://some.server.com

-----
 Results, create f1.html, f2.html:
Hlins version 0.39.
Number of insertions: 1

Open the attached HTML files in your browser to see the results.

The t2t can be found at the link given in the script above, and hlins was in the Debian repository.

Best wishes ... cheers, drl

Thank you I will try this

---------- Post updated at 03:20 PM ---------- Previous update was at 03:18 PM ----------

Thank you.
Can you please explain me what below does
printf("%s ", $i) and
>" $NF "</T

why $NF we user $ when we declare it before .
please explain for my knowledge

In awk the function call:

printf("%s ",  $i)

prints the contents of the ith field on the current input line followed by a <space> character.

In awk the command >" $NF "</T is a syntax error. The command:

       print "<TD>" $NF "</TD>";

prints the string <TD> followed by the contents of the last field on the current input line followed by the string </TD> followed by a <newline> character. In awk the $ operator refers to the contents of the field named by the number contained in the constant or variable that follows that operator. ( $0 refers to the contents of the entire current input line.)

1 Like