Compare sum of two columns if variance is zero do nothing else send an email


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Compare sum of two columns if variance is zero do nothing else send an email
# 22  
Old 06-02-2018
Sorry, for the wrong context here.

By any, I meant, different sets which are created every day with a similar format and equivalent structure.

Also, I want the output to be displayed in a separate file. So I added :

Code:
awk'...' Ariba.csv FS=, Pay.csv > outputfile.csv

at the end of the line and it works.

But if I want this outputfile to have an output of first sum, output of 2nd sum and variance. Do I have to print these in here?
Code:
if (SUM) print "Variance is not zero: ", SUM/100

# 23  
Old 06-02-2018
It's not that easy, it needs a slightly different approach: not count up and then down a single variable, but sum up first var, then second, and then print both and their difference.
Try and post here for discussion.

Last edited by RudiC; 06-02-2018 at 02:17 PM.. Reason: word missing
This User Gave Thanks to RudiC For This Post:
# 24  
Old 06-06-2018
New code

So after trying and trying, I found playing with awk little hard Smilie

So I tried a new approach.

here is the code...

Code:
#!/bin/bash/sh
a=0.000000
for value in `cat file1  | grep Total | tr -s " " " " | cut -d " " -f2`
do
a=$(echo $a + $value | bc)
done
echo "file1 : $a"
b=0.000000
for value2 in `cat file2 | cut -d "," -f7 | sed -e 's/^"//g' -e 's/"$//g'`
do
b=$(echo $b + $value2 | bc)
done
echo "file2 Total: $b"
if [ $a = $b ]
then
echo "Total is same"
fi

# 25  
Old 06-06-2018
How about (untested)


Code:
awk '
FNR == 1        {next
                }
FNR == NR       {if (/^Total/) SUM1 += $2*100
                 next
                }
                {SUM2 += $7*100
                }
END             {print SUM1/100, SUM2/100, "Variance: ", (SUM2 - SUM1))/100
                }
' Ariba.csv Pay.csv

# 26  
Old 06-09-2018
It works too.. but still the output is not in decimal.

I'm done with the code part and was able to add few more things..

I'll share my code here once i'm all done.. 5-10%of coding pending I can say.

I've a question:
My code as shared above(most recent one) is working fine but when the first row has the naming for the columns it doesn't work and throws syntax error.

Can you please help me with the command which elliminates/removes the first row of the file?
The file looks something like this:
Code:
PaymentId,InvoiceReconciliationId,PurchasingUnit,InvoiceNumber,InvoiceDate,Supplier,GrossAmount,GrossAmountCurrency,PaymentTerms,ForTaxAccrual,SupplierLocation,SupplierLocationContactID,RemittanceLocation,cus_ManualInvoiceNumber,cus_LocationCode_UniqueName,cus_EstimatePaymentDate,cus_CreateDate,cus_SupplierName,cus_PaymentDescription,cus_RequesterPIN
"PAYMXF5477-209123","IRMXF5477-209123",,"MXF5477","06/04/2018 05:09:00 -0700","5002362","110.6500","USD","Net 30","No","5002362","5002362","RL_INTERNAL50834041",,,,"Mon Jun 4 10:10:13 PDT 2018","CDW DIRECT LLC",,"1541"
"PAY81171-209097","IR81171-209097",,"81171","05/31/2018 09:23:00 -0700","VM1039342","5775.0000","USD","Net 00","No","VM1039342","VM1039342",,,,,"Mon Jun 4 09:24:22 PDT 2018","PAYSCALE INC",,"3661"
"PAYMXF5657-209126","IRMXF5657-209126",,"MXF5657","06/04/2018 05:11:00 -0700","5002362","24.9800","USD","Net 30","No","5002362","5002362","RL_INTERNAL50834092",,,,"Mon Jun 4 10:12:06 PDT 2018","CDW DIRECT LLC",,"7337"

# 27  
Old 06-09-2018
Use 1d; in the sed command.


What does "the output is not in decimal" mean?
This User Gave Thanks to RudiC For This Post:
# 28  
Old 07-13-2018
Code using sed

Sorry for the late reply, I have been busy with multiple things rn.

Thanks for the help Rudic!

Here is what I used...
I didn't delete the complete Row from the file, instead I just removed the Column name.
Code:
if [ $string == 'GrossAmount' ]; then

echo "$string"

sed -i '1d' $filename

fi

You were a great help!
Smilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Group by columns and add sum in new columns

Dear Experts, I have input file which is comma separated, has 4 columns like below, BRAND,COUNTRY,MODEL,COUNT NIKE,USA,DUMMY,5 NIKE,USA,ORIGINAL,10 PUMA,FRANCE,DUMMY,20 PUMA,FRANCE,ORIGINAL,15 ADIDAS,ITALY,DUMMY,50 ADIDAS,ITALY,ORIGINAL,50 SPIKE,CHINA,DUMMY,1O And expected output add... (2 Replies)
Discussion started by: ricky1991
2 Replies

2. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns satisfy the condition

HI All, I'm embedding SQL query in Script which gives following output: Assignee Group Total ABC Group1 17 PQR Group2 5 PQR Group3 6 XYZ Group1 10 XYZ Group3 5 I have saved the above output in a file. How do i sum up the contents of this output so as to get following output: ... (4 Replies)
Discussion started by: Khushbu
4 Replies

3. Shell Programming and Scripting

Compare 2 csv files by columns, then extract certain columns of matcing rows

Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns. I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
Discussion started by: bkane3
5 Replies

4. Shell Programming and Scripting

Get the SUM of TWO columns SEPARATELY by doing GROUP BY on other columns

My File looks like: "|" -> Field separator A|B|C|100|1000 D|E|F|1|2 G|H|I|0|7 D|E|F|1|2 A|B|C|10|10000 G|H|I|0|7 A|B|C|1|100 D|E|F|1|2 I need to do a SUM on Col. 5 and Col.6 by grouping on Col 1,2 & 3 My expected output is: A|B|C|111|11100 (2 Replies)
Discussion started by: machomaddy
2 Replies

5. Shell Programming and Scripting

Evaluate 2 columns, add sum IF two columns match on two rows

Hi all, I know this sounds suspiciously like a homework course; but, it is not. My goal is to take a file, and match my "ID" column to the "Date" column, if those conditions are true, add the total number of minutes worked and place it in this file, while not printing the original rows that I... (6 Replies)
Discussion started by: mtucker6784
6 Replies

6. UNIX for Dummies Questions & Answers

new to ldap, send email to a ou or group, and see a list from email client

hi, i'm running openldap on ubuntu 10.04, creating new items with apache directory studio (windows version). i use the ldap just as an address book to our small office (email clients are windows live mail 2009, 2011, microsoft outlook 2007 and 2010). a. i cant see a list of the contacts,... (0 Replies)
Discussion started by: V4705
0 Replies

7. Shell Programming and Scripting

Script to send email after comparing the folder permissions to a certain permission & send email

Hello , I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them . I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Discussion started by: nairshar
2 Replies

8. Solaris

Send an email from Solaris using Linux email server

Hello everyone I have a problem and I need your help: I have a Solaris 10 and Solaris 8 UNIX Servers, and Linux Centos4 as email server. I need send an email from Solaris servers preferably using Centos4 email server. I have no mail service configured in my Solaris computers (1 Reply)
Discussion started by: aflores
1 Replies

9. Shell Programming and Scripting

Sum of three columns - in 4N columns file

Hi All, happy new year. I have a file with 4xN columns like 0.0000e+00 0.0000e+00 7.199E+07 7.123E+07 6.976E+07 6.482E+07 5.256E+07 2.523E+07 0.0000e+00 0.0000e+00 8.641E+07 8.550E+07 8.373E+07 7.780E+07 6.309E+07 3.028E+07... (8 Replies)
Discussion started by: f_o_555
8 Replies

10. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies
Login or Register to Ask a Question