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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Required to get out put of log in tabular format in email body
# 8  
Old 07-26-2016
Quote:
Originally Posted by Ivo Breeden
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:
Code:
<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
Code:
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.
Moderator's Comments:
Mod Comment Please, as has been requested many times, use CODE tags (not ICODE tags) when displaying full-line and multi-line sample input, sample output, and code segments.

Last edited by Don Cragun; 07-26-2016 at 11:58 PM.. Reason: Change ICODE tags to CODE tags again.
# 9  
Old 07-27-2016
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.
# 10  
Old 07-27-2016
Quote:
Originally Posted by Don Cragun
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 &amp;lt;HTML&amp;gt; tag at the start of your file. There is no &amp;lt;/HTML&amp;gt; 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.&lt;br /&gt;<br />
&lt;br /&gt;<br />
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




Moderator's Comments:
Mod Comment Please edit this post removing those partial tags to make it readable!


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

Quote:
Originally Posted by mirwasim
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




Moderator's Comments:
Mod Comment Please edit this post removing those partial tags to make it readable!
Dear Don,

I have managed to get the html output in email with tabular format.
I used below script
Code:
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

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

But I want output like below

Code:
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
Code:
fixed inquiries - Click on MAX suffix http://server:port/app

Thanks in advance

Last edited by mirwasim; 07-27-2016 at 04:31 AM..
# 11  
Old 07-27-2016
Hello Mirwasim,
Your script is getting better.
Try this:
Code:
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:
Code:
<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.

Last edited by Ivo Breeden; 07-27-2016 at 05:48 PM.. Reason: forgot a space
This User Gave Thanks to Ivo Breeden For This Post:
# 12  
Old 07-28-2016
Hi.

I like to use extant codes. Here is a demonstration of t2t, automatic creation of HTML tables, and hlins to insert URLs:
Code:
#!/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
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.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

Last edited by drl; 07-28-2016 at 03:08 AM..
# 13  
Old 07-29-2016
Quote:
Originally Posted by drl
Hi.

I like to use extant codes. Here is a demonstration of t2t, automatic creation of HTML tables, and hlins to insert URLs:
Code:
#!/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
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.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 ----------

Quote:
Originally Posted by Ivo Breeden
Hello Mirwasim,
Your script is getting better.
Try this:
Code:
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:
Code:
<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.

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
# 14  
Old 07-29-2016
Quote:
Originally Posted by mirwasim
... ... ...
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:
Code:
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:
Code:
       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.)
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To have a mail in tabular format

Hello Guys, developing a monitoring shell script to have my queue depth count over mail . here is the sample input file to the script which has all the queue names 1 : DISPLAY QUEUE(*) WHERE (CURDEPTH GT 0) ZFC8409: Display Queue details. QUEUE(QL.GVR.ATA.CACHE.01) ... (10 Replies)
Discussion started by: wims
10 Replies

2. Shell Programming and Scripting

Adding a blank line in between two O/Ps in tabular format which gets received over email

Hi Guys, I am stuck in between and seeking help here. Requirement: A script that will run every morning which will connect to Mysql database and run the query to inform us about the holidays (it will also check if there were any holidays during last 2 business days). So the three queries are... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Fetching the required data out of a tabular form

Hello Gurus, I am trying to fetch a required number of lines from an output of a command which is in tabular form. Below is the command for reference along with how the result is being shown on UNIX shell. /usr/openv/volmgr/bin/vmquery -b -p 5 The result of the above command is as... (6 Replies)
Discussion started by: Ali Sarwar
6 Replies

4. Shell Programming and Scripting

Body content is in random format while sending email from Linux to my outlook.

Hi I have a script running in lunix machine which emails log file content to my outlook. Here is the actual log file result: Image-1 In-Master:25028 ReplicaDn Consumer Supplier Delay dc=xxx,dc=com lmjker0110:12345 ... (4 Replies)
Discussion started by: buzzme
4 Replies

5. Shell Programming and Scripting

Script to generate Excel file or to SQL output data to Excel format/tabular format

Hi , i am generating some data by firing sql query with connecting to the database by my solaris box. The below one should be the header line of my excel ,here its coming in separate row. TO_CHAR(C. CURR_EMP_NO ---------- --------------- LST_NM... (6 Replies)
Discussion started by: dani1234
6 Replies

6. Shell Programming and Scripting

Outlook Email Body Format Issue

Hello All, I been trying to get a solution for a while not able to figure out. I am generating a file and sending that as an body of message to my outlook account. For some reason reason everything is showing up as one line in the email. for i in `cat "${GEN_PARAM_LIST3}"` do ... (0 Replies)
Discussion started by: Ariean
0 Replies

7. Shell Programming and Scripting

Displaying output in the tabular format

Hi I want to display the following input data into the tabular format as shown in the output. Input.txt: Following jobs are in pending state for more than 10 minutes: JOB_ID JOB_SUBMIT_ID MAHAR 784308 PUNJA 109367 Following jobs are running for longer time: JOB_ID... (1 Reply)
Discussion started by: dats
1 Replies

8. UNIX for Dummies Questions & Answers

Put data in tabular form..

Dear Friends, I have a file as under : +++ ME 12-06-13 18:16:20 A RED FEW AND ROW1 1MN FEL AS HI FI BV LR TS HR ES MR * 0 13296 0 120 1 15 KS RR 10 0 +++ ME 12-06-13 18:26:20 A RED FEW AND ROW2 1MN FEL AS... (2 Replies)
Discussion started by: vanand420
2 Replies

9. UNIX for Dummies Questions & Answers

Put data into tabular form

Hi I am having a file which is required to be presented in the under-noted output form. Please suggest. Input: Kapil: apple 4 banana 6 cherry 0 Manoj: apple 13 banana cheery 2 Output: apple banana cherry Kapil: 4 6 0 Manoj: 13 2 Thanks in... (4 Replies)
Discussion started by: vanand420
4 Replies

10. Shell Programming and Scripting

how to put subject and body to mail from two files

Hi all, My sample file is something like this, ORA-00206: Message 206 not found; product=RDBMS; facility=ORA ORA-00202: Message 202 not found; product=RDBMS; facility=ORA ORA-27063: Message 27063 not found; product=RDBMS; facility=ORA ORA-00206: Message 206 not found; ... (1 Reply)
Discussion started by: sri1977
1 Replies
Login or Register to Ask a Question