Sponsored Content
Full Discussion: Difference script
Top Forums Shell Programming and Scripting Difference script Post 302418669 by aigles on Wednesday 5th of May 2010 04:43:48 AM
Old 05-05-2010
Try this new version (the function toStr is a little bit ugly) :
Code:
awk '

function abs(n) {
   return (n<0 ? -n : n)
}

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 = ""
   new  = toNum($3);
   if ($1 in Old && new != Old[$1] )
      diff = toStr(abs(new-Old[$1]), 15, 2);
   print $0 diff
}
' yday.txt today.txt

yday.txt
Code:
UNDOTBS1                                  15.00            10.00        5.00 
UNDOTBS2                                  20.00            15.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           2.00
UNDOTBS2                                  20.00            17.00        3.00           2.00
FOO                                        1.00             1.00        1.00
USERS                                      5.00             4.00        1.00           1.00
BONUS                                    777.00         3,333.33       33.00       2,222.22

Jean-Pierre.
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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

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

7. 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

8. 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

9. 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
uudemon(4)						     Kernel Interfaces Manual							uudemon(4)

NAME
uudemon.admin, uudemon.cleanu, uudemon.hour, uudemon.poll - Administrative shell scripts for polling remote systems, cleaning up spool directories, reporting status to the system administrator, and routine invocations of the uuxqt and uusched daemons SYNOPSIS
These shell scripts reside in the following directory: /usr/lib/uucp DESCRIPTION
All the scripts can be run from the command line or can be run automatically by the cron daemon. To automatically run the scripts, remove the comment character (#) from the beginning of the relevant line in the /var/spool/cron/crontabs/uucp file. This script reports status to the system administrator. It issues the uustat command to find out the status of uucp jobs. It mails the results to the uucp login ID. The script may be modified to send mail to any login ID such as the uucp administrative login ID (uucpa) or root. This script cleans up the /var/spool/uucp and /var/spool/uucppublic directories by running the uucleanup command. The uucleanup com- mand is run with the following parameters: -C7, -D7, X2, -o2, -W1. This script runs the uusched and uuxqt daemons in the background. This script polls the systems listed in the /usr/lib/uucp/Poll file. The uudemon.poll script should be scheduled before the uudemon.hour script. This allows uudemon.poll to create any command files before cron runs the uudemon.hour script. FILES
Contains the uudemon.admin, uudemon.cleanu, uudemon.hour and uudemon.poll files. Contains the uucp file. RELATED INFORMATION
Commands: cron(8), uucleanup(8), uusched(8), uuxqt(1) Files: /usr/lib/uucp delim off uudemon(4)
All times are GMT -4. The time now is 04:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy