Script to convert csv file to html with good visibility | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Script to convert csv file to html with good visibility

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-04-2012
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Script to convert csv file to html with good visibility

Hi,

I have Below script which converts csv file to html succesfully.but the visiblity is simple in black n white. I want to have better visibilty of each columns in different colours(like green).As it is a Database report suppose some tablespace available space is less than 20% then it should come up in red colour.If the available space is above 20% then it should come up in green.


Code:
perl -F',' -lane 'BEGIN{open O, ">output_db.html"; print O "<html><body><table border=1>"}; chomp;
print O "<tr>";
print O "<th>$_<\/th>" for (@F);
print O "<\/tr>";
END {print O "<\/table><\/body><\/html>"; close O}' DBA_CHECKS.csv


Your prompt help is much appreciated.

Moderator's Comments:
Please stop using ALL CAPS for your subject titles, and use code tags. Thanks


Moderator's Comments:
And while you're at it, please stop double posting and post in the currect forum.

Last edited by Scott; 10-04-2012 at 08:17 AM.. Reason: Code tags
Sponsored Links
    #2  
Old 10-04-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 September 2014, 12:09 PM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts

Code:
 
perl -F',' -lane 'BEGIN{
@bgc=("lightgreen","lightsteelblue");
open O, ">output_db.html"; print O "<html><body><table border=1><tbody>"
};
chomp;
print O "<tr>";
for $i (0..@F-1) {
   print O "<td bgcolor=" . @bgc[$i % 2] . " >@F[$i]<\/td>"
}
print O "<\/tr>";
END {print O "</tbody><\/table><\/body><\/html>"; close O}' DBA_CHECKS.csv

The Following User Says Thank You to rdrtx1 For This Useful Post:
sv0081493 (10-04-2012)
Sponsored Links
    #3  
Old 10-04-2012
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Hi rdrtx1,

Thanks a lot Script works great..
I had one query if you can help me.I have one column in that html report named "%Free" where it is showing how much % space is free.I want to add to that script suppose some tablespace %Free space is less than 20% then it should come up in red colour.If the %Free space is above 20% then it should come up in green.

Could you please help here.
    #4  
Old 10-04-2012
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 23 September 2014, 12:09 PM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
if the % column is # 2 (otherwise change $pct_col):


Code:
 
#!/bin/ksh
perl -F',' -lane 'BEGIN{
$pct_col=2;
@bgc=("lightgreen","lightsteelblue");
open O, ">output_db.html"; print O "<html><body><table border=1><tbody>"
};
chomp;
print O "<tr>";
for $i (0..@F-1) {
   $cbgc=@bgc[$i % 2];
   if (${i} == ($pct_col - 1)) {
      $pct=@F[$i];
      $pct=~s/ *[%].*$//;
      $pct=~s/^ *//;
      $cbgc="red" if ($pct <= 20);
   }
   print O "<td bgcolor=" . $cbgc . " >@F[$i]<\/td>"
}
print O "<\/tr>";
END {print O "</tbody><\/table><\/body><\/html>"; close O}' DBA_CHECKS.csv


Last edited by rdrtx1; 10-04-2012 at 12:10 PM..
The Following User Says Thank You to rdrtx1 For This Useful Post:
sv0081493 (10-04-2012)
Sponsored Links
    #5  
Old 10-05-2012
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Hi,

Hats off mate it worked like wonder.Now I want to understand how the script is working.Could you please briefly explain how the script goes.
Sponsored Links
    #6  
Old 10-05-2012
balajesuri's Avatar
balajesuri balajesuri is offline Forum Advisor  
#! /bin/bash
 
Join Date: Apr 2009
Last Activity: 25 October 2014, 7:44 AM EDT
Location: India
Posts: 1,831
Thanks: 25
Thanked 525 Times in 504 Posts
@sv0081493: Don't you think you should mention in Post #1, from where you got that perl code !
The Following User Says Thank You to balajesuri For This Useful Post:
sv0081493 (10-05-2012)
Sponsored Links
    #7  
Old 10-05-2012
sv0081493 sv0081493 is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 20 May 2014, 7:57 AM EDT
Posts: 58
Thanks: 34
Thanked 1 Time in 1 Post
Hi Balajesuri,

Sorry if anything goes wrong from my side I am new to this forum.. Yes I accept i should mention that but forgot to mention.I will take care of these things in future posting
Thanks a lot for your help.
The Following User Says Thank You to sv0081493 For This Useful Post:
balajesuri (10-05-2012)
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
Script to convert CSV file to HTML sv0081493 Shell Programming and Scripting 4 10-03-2012 08:37 AM
Need to convert datafeed to html using script ranjancom2000 Shell Programming and Scripting 3 06-25-2012 01:55 PM
Convert shell script output txt file to html table a12ka4 Shell Programming and Scripting 6 09-20-2011 04:12 AM
Awk script to convert csv to html zeebala1981 Shell Programming and Scripting 2 03-04-2010 01:25 PM
visibility of a variable in Perl script. Niroj Shell Programming and Scripting 1 12-18-2008 10:15 AM



All times are GMT -4. The time now is 02:57 PM.