Difference script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difference script
# 8  
Old 05-07-2010
Hi..

It has worked.Thanks a lot. Thanks you very much. I really appreciate your help.SmilieSmilieSmilie.

---------- Post updated at 04:47 PM ---------- Previous update was at 04:45 PM ----------

Hi..

It has worked.Thanks a lot. Thanks you very much. I really appreciate your help.SmilieSmilieSmilie.

---------- Post updated 05-07-10 at 12:57 PM ---------- Previous update was 05-06-10 at 04:47 PM ----------

Hi..

I have tried the script on the report, I see that there is a another change that needs to be made.
For the differnce of today-yest , is there any possibilty of having an negative sign , when the value of today.txt is less than that of yest.txt

Thanks once again.

Eg:

Code:
today.txt: 1200
yest.txt :  1500
o/p        : -300

# 9  
Old 05-07-2010
Code:
awk '

function toNum(s) {
   sub(/,/, "", s);
   return s+0;
}

function toStr(n, w, p        , str, sign, len, dec, num) {
   str = sprintf("%." p "f", n+0);
   if (str ~ /^[+-]/) {
      sign = substr(str, 1, 1);
      str  = substr(str,2);
   }
   dec = str;
   sub(/.*\./, "", dec);
   sub(/\..*/, "", str);
   num = "";
   for (len=length(str); len>3; len-=3) {
      num = "," substr(str, len-2, 3) num
   }
   num = substr(str, 1, len) num;
   sub(/^,/, "", num);
   return  sprintf("%" w "s", sign num "." dec);
}

NR==FNR { Old[$1] = toNum($3) ; next }
{
   diff = 0
   new  = toNum($3);
   if ($1 in Old && new != Old[$1] )
      diff = new-Old[$1];
   diff = toStr(diff, 15, 2);
   print $0,diff
}
' yday.txt today.txt

yday.txt :
Code:
UNDOTBS1                                  15.00           110.00        5.00 
UNDOTBS2                                  20.00         2,015.00        5.00 
FOO                                        1.00             1.00        1.00
USERS                                      5.00             3.00        2.00 
BONUS                                    123.45         1,111.11      200.00

today.txt :
Code:
UNDOTBS1                                  15.00            12.00        3.00
UNDOTBS2                                  20.00            17.00        3.00
FOO                                        1.00             1.00        1.00
USERS                                      5.00             4.00        1.00
BONUS                                    777.00         3,333.33       33.00

Output :
Code:
UNDOTBS1                                  15.00            12.00        3.00          -98.00
UNDOTBS2                                  20.00            17.00        3.00       -1,998.00
FOO                                        1.00             1.00        1.00            0.00
USERS                                      5.00             4.00        1.00            1.00
BONUS                                    777.00         3,333.33       33.00        2,222.22

Jean-Pierre.
# 10  
Old 05-07-2010
Thankyou again... Smilie

---------- Post updated at 05:03 PM ---------- Previous update was at 02:23 PM ----------

Hi,

This script is working fine on Linux, when i did try the same on SunOS, I am getting the below error:
Code:
awk: syntax error near line 3
awk: bailing out near line 3

Any Help..

Thanks.
# 11  
Old 05-07-2010
Quote:
Originally Posted by jjoy
Thankyou again... Smilie

---------- Post updated at 05:03 PM ---------- Previous update was at 02:23 PM ----------

Hi,

This script is working fine on Linux, when i did try the same on SunOS, I am getting the below error:
Code:
awk: syntax error near line 3
awk: bailing out near line 3

Any Help..

Thanks.
As always.... if on Solaris, use nawk or /usr/bin/xpg4/bin/awk instead of the o' broken '/usr/bin/awk'.

Last edited by vgersh99; 05-07-2010 at 08:52 AM..
# 12  
Old 05-07-2010
Thankyou..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to calculate difference of split and sum the difference

In the awk I am trying to subtract the difference $3-$2 of each matching $4 before the first _ (underscore) and print that value in $13. I think the awk will do that, but added comments. What I am not sure off is how to add a line or lines that will add sum each matching $13 value and put it in... (2 Replies)
Discussion started by: cmccabe
2 Replies

2. Shell Programming and Scripting

Difference in executing the script

Hi Team, a silly question. Let's say i have a script called xyz.ksh what is the difference in executing the script as follows? ./xyz.ksh ksh xyz.ksh Thanks (2 Replies)
Discussion started by: kmanivan82
2 Replies

3. Shell Programming and Scripting

Weird difference in script execution

Hi, So I have a very simple script which loops over 5 times and prints the iterator value. #!/bin/sh START=1 END=5 for i in $(eval echo "{$START..$END}") do echo "$i" done If I save this script in a .sh file and run it in the terminal, the output I get is {1..5} (4 Replies)
Discussion started by: jamie_123
4 Replies

4. Shell Programming and Scripting

What is difference between this two lines in script?

Hi Guys, What is difference between this two lines in script logger -p daemon.info -t postback Starting /opt/local/bin/backup-report and /opt/local/bin/backup-report is the backu script running twice here? Thanks, (2 Replies)
Discussion started by: manalisharmabe
2 Replies

5. Programming

what is the main difference between difference between using nonatomic lseek and O_APPEND

I think both write at the end of the file ...... but is there a sharp difference between those 2 instruction ..... thank you this is my 3rd question today forgive me :D (1 Reply)
Discussion started by: fwrlfo
1 Replies

6. Shell Programming and Scripting

Need script to output difference in folders

Hey everyone, I have two folders (folder1, folder2). Folder2 is a compiled version of a bunch of other folders including folder1. I want to compare folder1 to folder2 to make sure that folder2 contains all of the contents of folder1. If it does not, I would like the script to output... (5 Replies)
Discussion started by: chango77747
5 Replies

7. Shell Programming and Scripting

AWK Script and Commandline difference

Hey there, I just stumbled upon a difference between using awk on the commandline and using it in a shellscript. I have a variable, e.g.: PROG=vim then i want to check if the package with this name is installed: TEMPVAL=$(dpkg -l | awk '{ if ($2 == "$PROG") print $2 }') (Im using... (10 Replies)
Discussion started by: MrSnail
10 Replies

8. Shell Programming and Scripting

Script to display time difference..

Hi i've written a script which reads last two line of the log file from N number of servers and send the mail by redirecting to a particular log file. And the two lines is displayed below. Oracle Q03 Begin Hot BACKUP Time: 07/23/08 18:35:46 Oracle Q03 End Hot BACKUP Time: 07/24/08 14:18:15... (1 Reply)
Discussion started by: suri.tyson
1 Replies

9. Shell Programming and Scripting

Difference in Executing a Script

Can anyone tell me the difference between the following execution ways: 1) . ./filename 2) ./filename Also when to use the either. (8 Replies)
Discussion started by: Shivdatta
8 Replies
Login or Register to Ask a Question