Dushan Silva
asked on
URGENT: Read CSV file and altert details via formatted email(python or unix shell script)
I'm having following csv file format and I want to read that file and should send email alters if last two column values are difference
------------------csv file------------------
Query,group,IBM,product
Clam,Senehasa,12345,12345
Jane,SSC,23456,23457
Mmettha,SSC,34567,34566
-------------------------- ---------- --------
first line of this csv file contains titles of columns.
If there is any count difference between last two columns(IBM and product) then email alert should send, mentioning that particular row with details and it should be in red color as attached image with additional delta field.
Also error handling(while reading csv file and sending emails) should write to a log file.
delta.jpg
------------------csv file------------------
Query,group,IBM,product
Clam,Senehasa,12345,12345
Jane,SSC,23456,23457
Mmettha,SSC,34567,34566
--------------------------
first line of this csv file contains titles of columns.
If there is any count difference between last two columns(IBM and product) then email alert should send, mentioning that particular row with details and it should be in red color as attached image with additional delta field.
Also error handling(while reading csv file and sending emails) should write to a log file.
delta.jpg
Are you asking for help, or for someone to write your entire script for you? Have you attempted anything? Where are you stuck?
ASKER
https://www.experts-exchange.com/questions/26557987/URGENT-Read-CSV-file-and-altert-details-via-formatted-email-UNIX-SHELL-SCRIPT.html
https://www.experts-exchange.com/questions/26557443/URGENT-Read-CSV-file-and-altert-details-via-email-UNIX-SHELL-SCRIPT.html
https://www.experts-exchange.com/questions/26559441/Read-CSV-file-and-altert-details-via-formatted-email-UNIX-SHELL-SCRIPT.html
https://www.experts-exchange.com/questions/26557443/URGENT-Read-CSV-file-and-altert-details-via-email-UNIX-SHELL-SCRIPT.html
https://www.experts-exchange.com/questions/26559441/Read-CSV-file-and-altert-details-via-formatted-email-UNIX-SHELL-SCRIPT.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've already found csv reading scripts. But I face difficulties with only sending these data in HTML formatted email. Please advise.
ASKER
I worked on following script.
#!/bin/sh
if awk 'BEGIN {
FS = ","; x=1; y=1};
NR > 1 {if ($4!=$3) {
if (y%2==0){
print "<tr style=!background: #ADABB3!><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td><td>" $4 "</td><td style=!background: #F1595A!>" $4-$3 "</td></tr>";}
else {
print "<tr style=!background: #EAEAEA!><td>" $1 "</td><td>" $2 "</td><td>" $3 "</td><td>" $4 "</td><td style=!background: #F1595A!>" $4-$3 "</td></tr>";}
y=y+1;
}
};
END {exit(x)}' |tr @! \"\' > tmpfile
then
(echo 'To: abc@abc.com
Subject: Discrepancies between 'ICS' & 'Native Products' Indexes
Content-Type: text/html; charset="us-ascii"
<html>
<table border="1" bordercolor="#000000"" width="100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#7B7881">
<th>Cluster</th>
<th>Query</th>
<th>Data Results</th>
<th>Product Results</th>
<th>Results Δ </th>
</tr>'
cat tmpfile
echo '</table>
</html>') > tmpfile2 && echo "Sending mail" && /usr/sbin/sendmail prr@pqr.com,klm@pqr.com,prd@pqr < tmpfile2
fi
ASKER
Solution found by myself with help from given details