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.

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.

 
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
1 Like

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.

if the % column is # 2 (otherwise change $pct_col):

 
#!/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
1 Like

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.

@sv0081493: Don't you think you should mention in Post #1, from where you got that perl code !

1 Like

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.

1 Like

it works absolutely great. I am a newbie to perl . Could you please explain the program in detail . thank you in advance