vendredi 30 août 2019

Changing column colors based on conditions in HTML table

I am trying to send email using bash script in a HTML format.

The column names are below

Portfolio
account_number
critical
distinct_file_name_count
total_file_count
Files_validation

AWK command used to populate the .HTML file

awk -F"#" '
    BEGIN {
        print "<html><head>\
            <style>\
                body {\
                    background-color: #FFF;text-align:left;\
                    }\
                        table {\
                            font-family:Tahoma;\
                            font-size:11;\
                            border-collapse:collapse;\
                            border: 4px solid #dddddd;\
                        }\
                        th { padding:10px;\
                            background-color: #94E1F7;\
                        }\
                            th { border: 1px solid black;\ 
                        }\
                        td {\
                            padding:3px;\
                            border: 2px solid black;\
                            text-align:right;\
                        }\
                            </style>\
                        </head>\
                        <body>\
                            <table>\
                                <tr>\
                                    <th>Portfolio</th> 
                                    <th>account_number</th> 
                                    <th>critical</th> 
                                    <th>distinct_file_name_count</th> 
                                    <th>total_file_count</th> 
                                    <th>Files_validation</th> 
                                </tr>" 
} 
{ 
    print "<tr>" 
    printf "<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>",$1,$2,$3,$4,$5 
    for (i = 6; i < 7; i++) { 
        if ($i == "Files_not_received_today") { 
            printf "<td bgcolor=#FF0000>%s</td>",$i 
        } else { 
            printf "<td bgcolor=#32CD32>%s</td>",$i 
        }
    } print "</tr>" 
} END { 
    print "</table></body></html>"
}' ${run_project_tmp_dir}/QC_VALIDATION_REPORT.txt >> ${run_project_tmp_dir}/QC_VALIDATION_REPORT.html

Condition I want to make the change is that

1) When column when `Files_validation` column is having `Files_not_received_today` then check if `critical` column is `YES`. 

If `YES` then Populate `RED` color in both `Files_validation` and `critical`. Else if  when `Files_validation` column is having `Files_not_received_today` then check if `critical` column is `NO` then Populate `AMBER` color in both `Files_validation` and `critical`.

2)  when `Files_validation` column is having other than `Files_not_received_today` Populate `GREEN` color in `Files_validation`

With the above awk command I am able to populate the Files_validation with RED and GREEN colors based on my expectations but unable to achieve my desired result of the conditions mentioned

Aucun commentaire:

Enregistrer un commentaire