Hello Vijay,
Below a little script. I hope it works like you expected. Please let me know when I can help you to change this script to your needs.
==============================================
#!/bin/ksh
#Set temp. time zone to +24 hours to get date of yesterday
CURRTZ=$TZ
TZ=NFT+24
MOUNTH=$(date +"%m")
DAY=$(date +"%d")
#Grep for recs with sysdate - 1st rec
cat FileA |grep $MOUNTH/$DAY > FileA.yesterday
cat FileB |grep $MOUNTH/$DAY > FileB.yesterday
#For loop for all the the Table differences of yesterday's numbers.
for TableItem in $(diff FileA.yesterday FileB.yesterday |grep Table |awk -F'~' '{print $1}' |awk '{print $2}' |sort |uniq)
do
#Take the difference of FileA & FileB count
FA=$(cat FileA.yesterday |grep $TableItem |awk -F '~' '{print $3}')
FB=$(cat FileB.yesterday |grep $TableItem |awk -F '~' '{print $3}')
COUNTDIFF=$(expr $FA - $FB |sed "s/-//g" ) #sed remove the "-" sign
#Print result in new file
echo $TableItem $COUNTDIFF > New.File
done
#Extra: Set the time zone(TZ) back. This is not really necessary. We did not export the earlier TZ
export TZ=$CURRTZ
==============================================
Quote:
Originally Posted by
vijayarajvp
Hi,
I need someone's help in writing a shell script. Since am very new i am stuck .
I have 2 files in the same dir.
==============================================
FileA
Table1~07/07/2009 00:00:00~4
Table1~07/06/2009 00:00:00~41
Table1~07/08/2009 00:00:00~4
Table2~07/08/2009 00:00:00~4
FileB
Table1~07/07/2009 00:00:00~4
Table1~07/06/2009 00:00:00~44
Table1~07/08/2009 00:00:00~4
Table2~07/08/2009 00:00:00~4
============================================
I am looking to take the data from both files in this manner.
Based on the timestamp i need take the rec, i.e if there are 3 days 6,7 & 8 (8 is today's date) then i need to take the rec of yesterday's i.e.7 (sysdate-1 th rec) from both files.
Table1 from both files for date 7 & at the end in file is the count (i.e 41 in fileA & 44 in fileB) are the counts.
I need to find the difference of them (fileB - fileA)
& i need the o/p in this format :
Table1 3 (in a new file)
so steps are :
Grep for recs with sysdate - 1st rec
Take the Tb name & count from both files
Take the difference of fileA & fileB count
Print it in a new file.
If some one can help me out in this, it would be of great help.
I tried like this :
I had 2 files a and b
a :
SVC_REQ_CNT~07/05/2009 00:00:00~16
SVC_REQ_CNT~07/06/2009 00:00:00~10
SVC_REQ_CNT~07/07/2009 00:00:00~18
SVC_ORD_CNT~01/22/2098 00:00:00~2
SVC_ORD_CNT~02/04/2099 00:00:00~2
SVC_ORD_CNT~07/07/2009 00:00:00~1
b :
SVC_REQ_CNT~07/05/2009 00:00:00~16
SVC_REQ_CNT~07/06/2009 00:00:00~10
SVC_REQ_CNT~07/07/2009 00:00:00~19
SVC_ORD_CNT~01/22/2098 00:00:00~2
SVC_ORD_CNT~02/04/2099 00:00:00~2
SVC_ORD_CNT~07/07/2009 00:00:00~5
I tried the following :
grep `TZ=aaa24 date +\%m/%d/%Y` a | cut -d '~' -f 3-4
o/p :
18
1
grep `TZ=aaa24 date +\%m/%d/%Y` b | cut -d '~' -f 3-4
19
5
Now i have to proceed further. Take the diff & put it in a new file along with the tb name ..
Thanks,
Vijay.