Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 04-06-2012
Registered User
 
Join Date: Dec 2011
Posts: 69
Thanks: 8
Thanked 0 Times in 0 Posts
How to generate html reports through LINUX Scripting?

Hi All,

I am trying to generate a weekly HTML report using LINUX Scripting. This will have record counts of some files. (like below)


Code:
touch path/filename.html
echo  "Weekly Summary Report for Business Date : $P_BUS_DT">path/filename.html
export A1=`cat path/filename1.txt |wc -l`
echo  "A1 Groups : $A1">>path/filename.html
export A2=`cat path/filename2 |wc -l`
echo  "A2 Groups : $A2">>path/filename.html
etc...

But, this is generating a one line report like below
A1 : 100 A2:200

I want to generate it in 2 lines,
A1:100
A2:200

Is there a way I can generate html file in this way ?

Any help/thoughts will be helpful to resolve this issue.

Thanks much
Freddie

Last edited by joeyg; 04-06-2012 at 12:54 PM.. Reason: Please wrap code and data in CodeTags
Sponsored Links
    #2  
Old 04-06-2012
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Location: Out running a Marathon.
Posts: 2,215
Thanks: 53
Thanked 134 Times in 126 Posts
Wondering about LF/CR issues

Can you:

Code:
od -bc filename.html

and post the result here?
(Remember to wrap the output with CodeTags)
Sponsored Links
    #3  
Old 04-06-2012
Registered User
 
Join Date: Dec 2011
Posts: 69
Thanks: 8
Thanked 0 Times in 0 Posts
How to generate html reports through LINUX Scripting

Hi Joey,

Thanks a lot for your quick response. Here s what I could see when i did an od -bc filename.html .

I am sorry if pasting the output will cause any issues, I am not sure how I can add code tags to the output.


Code:
0000000 103 120 115 107 040 127 145 145 153 154 171 040 123 165 155 155
          C   P   M   G       W   e   e   k   l   y       S   u   m   m
0000020 141 162 171 040 122 145 160 157 162 164 040 146 157 162 040 102
          a   r   y       R   e   p   o   r   t       f   o   r       B
0000040 165 163 151 156 145 163 163 040 104 141 164 145 040 072 040 015
          u   s   i   n   e   s   s       D   a   t   e       :      \r
0000060 012 124 157 164 141 154 040 111 156 151 164 151 141 154 040 123
         \n   T   o   t   a   l       I   n   i   t   i   a   l       S
0000100 165 163 160 145 143 164 163 040 072 040 063 061 071 061 060 064
          u   s   p   e   c   t   s       :       3   1   9   1   0   4
0000120 015 012 115 122 103 040 061 040 107 162 157 165 160 163 040 072
         \r  \n   M   R   C       1       G   r   o   u   p   s       :
0000140 040 063 060 015 012 115 122 103 040 110 040 107 162 157 165 160
              3   0  \r  \n   M   R   C       H       G   r   o   u   p
0000160 163 040 072 040 060 015 012 104 165 160 154 151 143 141 164 145
          s       :       0  \r  \n   D   u   p   l   i   c   a   t   e
0000200 040 122 145 143 157 162 144 163 040 072 040 060 015 012
              R   e   c   o   r   d   s       :       0  \r  \n
0000216

Thanks in advance,
Freddie

Moderator's Comments:
Please use code tags. Video tutorial on how to use them

Last edited by Scrutinizer; 04-06-2012 at 02:43 PM..
    #4  
Old 04-08-2012
Registered User
 
Join Date: Dec 2011
Posts: 69
Thanks: 8
Thanked 0 Times in 0 Posts
Hi Joey,

Can you lpls et me know your thoughts on this.

Thanks Much
Freddie
Sponsored Links
    #5  
Old 04-08-2012
agama agama is offline Forum Advisor  
Always Learning
 
Join Date: Jul 2010
Location: earth>US>UTC-5
Posts: 1,466
Thanks: 110
Thanked 501 Times in 480 Posts
You need to generate a complete HTML document. Check out the tutorial here: HTML Tutorial

In short you need something along these lines:


Code:
(
  printf "<html>\n<head>\n<title>doument title</title>\n</head>\n<body>\n"
  echo  "Weekly Summary Report for Business Date : $P_BUS_DT"
  A1=`wc -l <path/filename1.txt `
  echo  "A1 Groups : $A1 <break>"
  A2=`wc -l <path/filename2 `
  echo  "A2 Groups : $A2"
  printf "</body>\n</html>\n"
) >path/filename.html

You'll also need to read up on how to properly format your output. For instance, if the output of any of your commands contains a greaterthan symbol (>) for instance, you'll need to convert it to a proper representation so that it is not interpreted by the browser as a part of HTML syntax.

If that's too much, then if you create a file with a .txt extention, most browsers render that as though it were contained in a complete HTML document with <pre> and </pre> tags around it.

Last edited by agama; 04-08-2012 at 09:43 PM.. Reason: removed useless uses of cat that I didn't catch in the original post
Sponsored Links
    #6  
Old 04-08-2012
Neo's Avatar
Neo Neo is offline Forum Staff  
Administrator
 
Join Date: Sep 2000
Location: Asia pacific region
Posts: 11,592
Thanks: 324
Thanked 628 Times in 261 Posts
IMO, before an inexperienced coder attempts to generate an HTML report from system commands, they should first create a script to generate a proper "Hello World" HTML page.

If you can create a "Hello World" HTML page, then it would be easy to then add more features, like output from a system command, etc.
Sponsored Links
    #7  
Old 04-09-2012
Registered User
 
Join Date: Dec 2011
Posts: 69
Thanks: 8
Thanked 0 Times in 0 Posts
Thanks Agama & Neo for your inputs.

I will try creating a simple HTML page.

In the meantime, currently I am creating this report as .rtf extension as all the lines in the output file was coming as one single line.(I have attached it for your reference). I can create this report as .txt & convert it to html through a simple (mv *.txt to *.html) command. But wondering whether there is a way to get the output in multiple lines through some simple workaround rather than going with the HTML tags etc.

Thanks much
Freddie
Attached Files
File Type: html CPMG_wklysummRpt..html (200 Bytes, 2 views)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
generate tabular output from an input text file in unix shell scripting pkbond Shell Programming and Scripting 7 04-04-2011 03:44 AM
Installation of Oracle Reports 6i on Linux Pavan Pusuluri UNIX and Linux Applications 0 06-22-2009 10:13 PM
how to use html tag in shell scripting jrex1983 Shell Programming and Scripting 5 11-17-2008 08:13 PM
Generate report in HTML file from Oracle DB Amit.Sagpariya Shell Programming and Scripting 4 10-20-2008 05:47 AM
how to generate html file using script? kittusri9 Shell Programming and Scripting 2 05-25-2008 11:38 PM



All times are GMT -4. The time now is 08:26 PM.