Hi,
I have a csv file from which i am fetching few columns as below:
IFILE=/home/home1/Report1.csv
OFILE=/home/home1/`date +"%m%d%y%H%M%S"`.dat
if [ -r $IFILE ] #Checks if file exists and readable
then
awk -F "," '(NR>4) {print $1,$6,$2,$3,$4,$5,$6}' ${IFILE} >> ${OFILE}
fi
cat $OFILE | mail -s "Error report" abc@gmail.com
I want the output in tabular form
Could you please let us know the input and expected output for same.
Thanks,
R. Singh
I/P:
csv file:
column1 column 2 column 3
abc def ghi
Output should be in tabular form like we have in excel..use table format option.
It should have lines forming tables and in that data should be there
How about this:
IFILE=/home/home1/Report1.csv
awk -F, '
BEGIN{
c=split("1,6,2,3,4,5,6", col)
print "To: abc@gmail.com"
print "Subject: Error report"
print "MIME-Version: 1.0"
print "Content-Type: text/html"
print "Content-Disposition: inline\n"
print "<HTML><TABLE border=1>"
print "<TH>Heading 1</TH><TH>Heading 2</TH><TH>Heading 3</TH>"
print "<TH>Heading 4</TH><TH>Heading 5</TH><TH>Heading 6</TH>"
print "<TH>Heading 7</TH>"
}
NR>4 {
printf "<TR>"
for(i=1;i<=c;i++) printf "<TD>%s</TD>", $col
print "</TR>"
}
END{
print "</TABLE></BODY></HTML>"
} ' ${IFILE} | sendmail -t
1 Like
Thanks all.
The last html code works..
I just need to put one more condition ie mail should be sent only if column 6 and column 7 is not equal to 0. what needs to be done for that..
Thanks.
This will send the email if ANY row has non-zero in BOTH field 6 and 7:
IFILE=/home/home1/Report1.csv
if ! awk -F, '$6!=0&&$7!=0{exit 1}' ${IFILE}
then
awk -F, '
BEGIN{
c=split("1,6,2,3,4,5,6", col)
print "To: abc@gmail.com"
print "Subject: Error report"
print "MIME-Version: 1.0"
print "Content-Type: text/html"
print "Content-Disposition: inline\n"
print "<HTML><TABLE border=1>"
print "<TH>Heading 1</TH><TH>Heading 2</TH><TH>Heading 3</TH>"
print "<TH>Heading 4</TH><TH>Heading 5</TH><TH>Heading 6</TH>"
print "<TH>Heading 7</TH>"
}
NR>4 {
printf "<TR>"
for(i=1;i<=c;i++) printf "<TD>%s</TD>", $col
print "</TR>"
}
END{
print "</TABLE></BODY></HTML>"
} ' ${IFILE} | sendmail -t
fi
If both the rows are 0 still mail is coming.