return counting per hour percentage


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting return counting per hour percentage
# 1  
Old 08-19-2011
return counting per hour percentage

We have a monitoring process for a load in unix box, during this process we are writing logs statements for each record, and during this process we are showing the counts per hour. Here is that how we are following

log files statements: (just two lines printed here), these statements logged at 08:09 AM

08-19 08:09:32 APIDBManager 12752 INFO Successfull saving person to database, the saved ID: 114285
08-19 08:09:32 APIDBManager 12752 INFO Successfull saving person to database, the saved ID: 114286

Command to get the counts per each hour (time):
> grep 'Successfull saving person to database, the saved ID:' api_database_manager.log | awk '{ print $2 }' | awk -F':' '{ print $1 }' | uniq -c
>
20587 08
23102 09
So the above command gave the 20587 saved counts between 08:00 AM & 08:59 and 23102 saved counts between 09:00 & 09:59.

Here it good so far, but we see some counts in difference between hours 08 and 09. For this we need to display the percentage of counts increased or decreased (in -ve), so please how do we get this from command? You advice is very important to grab the attention from my top.
# 2  
Old 08-19-2011
I am guessing here, that you have 2 files and you want to display increased or decreased count for each year. For example 2 files like below /tmp/y1 and /tmp/y2

Quote:
$ cat /tmp/y1
20587 08
23102 09

and

$ cat /tmp/y2
20500 08
23000 09
The below does a difference between the same years, so 08 is matched in both files and the difference is displayed.
for example for 08, (20587-20500=)87 is displayed and so for each year.

Code:
gawk 'NR==FNR{a[$2]=$1;b[i++]=$2;next} {for(var in b) if(b[var]==$2) print (a[$2]-$1)}' /tmp/y1 /tmp/y2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

2. Shell Programming and Scripting

Percentage calculation

Hi, I have a text file in below format. I trying to find a solution for finding percentage used for each of the NAMEs. Directory ALLOCATED USED NAME1 93MB 93KB NAME2 25G 62K NAME3 14G 873M NAME4 25G 62K NAME5 20G... (10 Replies)
Discussion started by: ctrld
10 Replies

3. Shell Programming and Scripting

Need to monitor OS in percentage

Hi, I am looking for generic commands / scripts that could run across platforms especially on HP Itanium boxes to give me % of free OS parameters For eg: Free Total Memory RAM : 20 % Free Total Swap Memory: 35% Free Total CPU utilisation: 44% Free Disk Space: /appl = 55%... (5 Replies)
Discussion started by: mohtashims
5 Replies

4. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

5. Shell Programming and Scripting

counting word xx referred to a time period, like minute or hour

Hello, I try to insert a post because I've got a trouble to perform a unix job. But I didn't found which steps (procedure) I should follow. Could you help me? I got a log by my Application box, like following: gbosmam037:test >view Log_Server.csv ... (2 Replies)
Discussion started by: maluca68
2 Replies

6. Shell Programming and Scripting

Counting average data per hour

Hi i have log like this : Actually i will process the data become Anybody can help me ? (6 Replies)
Discussion started by: justbow
6 Replies

7. UNIX for Dummies Questions & Answers

percentage

How to calculate percentage of two values in unix. (5 Replies)
Discussion started by: venkatesht
5 Replies

8. Shell Programming and Scripting

How can i calculate percentage ??

i have 3 files like total.dat=18 equal.dat=14 notequal.dat=16 i need find the equal percentange means: equalpercentage = ($equal.dat / $total.dat * 100) How i can do this ? I tried some of the answers to calculate the percentage in this forums.but it couldn't worked.Some one please... (6 Replies)
Discussion started by: bobprabhu
6 Replies

9. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

10. UNIX for Dummies Questions & Answers

an hour less in 24 hour system

My program: __________________________________ #!/bin/ksh DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` day=`date +%m/%d/%y` let h=$H-1 echo DAY $DAY echo H $H echo M $M echo day $day echo h $h _____________________________________ My result: (3 Replies)
Discussion started by: bobo
3 Replies
Login or Register to Ask a Question