Comparing rows in two tables and sending the differnce to mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing rows in two tables and sending the differnce to mail
# 1  
Old 12-09-2008
Comparing rows in two tables and sending the differnce to mail

Hi,

I have a table ,containg 2 coloumns and many rows,which is updated everyday.The no.of rows in the table changes everyday.
i have to write the difference between yesterdays tabtle and todays table
to a new file.The row that is new in the todays table need not to be shown.only the change in the values from yesterdya to today should be shown.



ex:
yesterday table 1 2
3 4
6 8

todays table 1 2
5 4
6 9
2 5

I have to write the script in a such a way that ,
The output file should show

in coloumn1 3 is changed to 5
and in coloumn2 8 is changed to 9


and the outputfile has to be sent the mail id.

Please help me,
Thanks.
# 2  
Old 12-11-2008
Try this:

Code:
awk '
        NR==FNR { yesterday[NR,1]=$1; yesterday[NR,2]=$2; max=NR; next }
        FNR <= max && $1 != yesterday[FNR,1] {
                print "in column1",yesterday[FNR,1],"is changed to",$1
        }
        FNR <= max && $2 != yesterday[FNR,2] {
                print "in column2",yesterday[FNR,2],"is changed to",$2
        }
' yesterday today

# 3  
Old 12-12-2008
this seems to be something that could be done easily with

CPAN's List::Compare module

where yesterday's data and today's data would be two set of lists and methods provided to retrieve required data can be used
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing two tables

I have defined a set of global variables at the beginning of my script as below: #ideal values export ITEM1=SUCCESS export ITEM2=FAILURE export ITEM3=UNAVAILABLE export ITEM5=FAILURE export ITEM6=SUCCESS now I have a shell script function which returns a value in below format. ITEM1... (1 Reply)
Discussion started by: ctrld
1 Replies

2. Shell Programming and Scripting

UPDATE COmmand post comparing 2 columns in 2 mysql tables

my queryis : select distinct m.name, item_count, item from master m join client p on m.name=p.name where item_count = 1 and item > 1; But how should I update them? i used update statetment : Update from client Set item =1 where m.name=p.name and item_count=1 AND item>1 Is this wrong? (1 Reply)
Discussion started by: siya@
1 Replies

3. UNIX for Dummies Questions & Answers

Comparing rows

Hi, I have txt file below 02.05.2014,10.05.2014,dfs,srtytr,tyhty 05.10.2014,15.10.2014,456ef,t6y5fgtd,xg45t 21.11.2014,28.11.2014,sefser,dfw344,zsdfrw 22.12.2014,30.12.2014,fwe,aerw4,zwq4q my script will ask two input, enter start date 05.10.2014 enter end date... (3 Replies)
Discussion started by: stew
3 Replies

4. Red Hat

Problems sending mail: Difference between Mail and Mailx?

Whats the difference between mail and mailx? I'm trying to troubleshoot a problem where I can send mail from server A with this `echo $MESSAGE | mail -s "$SUBJECT" -r $FROM $RECIPIENTS` command but executing the same command from server B throws me this error (Both servers are RHEL) ... (1 Reply)
Discussion started by: RedSpyder
1 Replies

5. Shell Programming and Scripting

Help comparing 2 files and sending differences

I have 2 files that need to be compared. Email the differences if something is different and don't email if nothing is different. One or both of the files could be empty. One or both could have data in them. example files backup.doc.$(date +%y%m%d) file size is 0 backup.doc.$(TZ=CST+24... (4 Replies)
Discussion started by: jabbott3
4 Replies

6. Shell Programming and Scripting

Show only new and removed records by comparing to MySQL tables

Hello all; I have been really frustrated with finding the correct perl code (and MySql statements) to accomplish what I thought was straight forward...I have tested I don't know how many different codes\suggestions I found on the net without any success...but anyhow let me explain my plight and... (0 Replies)
Discussion started by: gvolpini
0 Replies

7. Shell Programming and Scripting

Stop sending mail after certain number of mail

Hi guys... I am busy writing a script to notify me via an mail if my application is down. I have done that. Now I want this script to stop sending mails after five mails were sent but the script should keep on checking the application. When the application is up again that count should be... (5 Replies)
Discussion started by: Phuti
5 Replies

8. Shell Programming and Scripting

Shell script for comparing data of tables

Hi, I have two databases with same tables on different servers.I need to check the data content in each table and if something is missing, should print that. I have a tool which takes the snapshot the table structure,index so on and compares with the other server tables snapshot. Now i need... (1 Reply)
Discussion started by: nessj
1 Replies

9. Shell Programming and Scripting

comparing two tables

I am comparing two table structure in different databases,Put into 2 txt files , when comparing if column sequnce and data type is not matching ,it has to display that info else Table structure is ok. wrote shell script ,its not working .I am getting "Table structure is not ok" even if both... (1 Reply)
Discussion started by: akil
1 Replies

10. UNIX for Dummies Questions & Answers

sending a mail to a mail client

Hi everyone! I'm trying to create a database monitoring script that reads an alert file and sends an error message if it can 'grep' a particular string. Is there a way to send this message to a mail client using SMTP? Even better, is there any place on this site that has these kinds of... (5 Replies)
Discussion started by: solaris73
5 Replies
Login or Register to Ask a Question