Link to home
Start Free TrialLog in
Avatar of Dushan Silva
Dushan SilvaFlag for Australia

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
Avatar of kaufmed
kaufmed
Flag of United States of America image

Are you asking for help, or for someone to write your entire script for you? Have you attempted anything? Where are you stuck?
Avatar of Dushan Silva

ASKER

ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've already found csv reading scripts. But I face difficulties with only sending these data in HTML formatted email. Please advise.
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 &#916; </th>
  </tr>'
cat tmpfile
echo '</table>
</html>') > tmpfile2 && echo "Sending mail" && /usr/sbin/sendmail prr@pqr.com,klm@pqr.com,prd@pqr < tmpfile2
fi

Open in new window

Solution found by myself with help from given details