awk to calculate timex output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk to calculate timex output
# 1  
Old 08-17-2012
awk to calculate timex output

I have a
Code:
timex

'dd' command that generates an output similar to this:

Code:
real 701.92
user 3.06
sys  469.10

for the moment, i m redirecting the output to a temp file to stage the calculation (using bc) for:
a) MB/s
b) cpu usage = 100*(user+sys)/real

I am looking around for an 1-liner
Code:
awk

to do the same, hopefully. Thanks in advance.

---------- Post updated 08-17-12 at 02:27 AM ---------- Previous update was 08-16-12 at 09:31 AM ----------

Got it working with this snippet:

Code:
    +1  #!/bin/ksh
    +2  cat timex2.out | \
    +3  awk '{
    +4  if ($1 ~ /real/) real=$2;
    +5  else if ($1 ~ /user/) user=$2;
    +6  else if ($1 ~ /sys/) sys=$2;
    +7  } END {
    +8  print 6144/real " MB/s " 100*(user+sys)/real "%" ;
    +9  }'


Last edited by ux4me; 08-17-2012 at 04:26 AM..
# 2  
Old 08-17-2012
Quote:
Originally Posted by ux4me
I am looking around for an 1-liner awk to do the same, hopefully. Thanks in advance.
Code:
$ awk -vRS= '{printf("%.1f MB/s %.1f%%\n",6144/$2,100*($4+$6)/$2)}' timex2.out
8.8 MB/s 67.3%

This User Gave Thanks to neutronscott For This Post:
# 3  
Old 08-20-2012
What if I want to substitute 6144 with a shell variable? For example:

Code:
fsize=6144

How would I pass the fsize variable into this 1-liner?

Code:
awk -vRS= '{printf("%.1f MB/s %.1f%%\n",6144/$2,100*($4+$6)/$2)}' timex2.out

Please advise and thanks again.
# 4  
Old 08-20-2012
Code:
awk -vRS= -vfsize="$fsize" '{printf("%.1f MB/s %.1f%%\n",fsize/$2,100*($4+$6)/$2)}' timex2.out

This User Gave Thanks to elixir_sinari For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to calculate average of all files in directory and output by part of filename

I am trying to use awk to calculate the average of all lines in $2 for every file in a directory. The below bash seems to do that, but I cannot figure out how to capture the string before the _ as the output file name and have it be tab-delimeted. Thank you :). Filenames in... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Calculate Average AWK

I want to calculate the average line by line of some files with several lines on them, the files are identical, just want to average the 3rd columns of those files.:wall: Example file: File 1 001 0.046 0.667267 001 0.047 0.672028 001 0.048 0.656025 001 0.049 ... (2 Replies)
Discussion started by: AriasFco
2 Replies

3. Shell Programming and Scripting

Calculate N days from a file output

OK, here is the output from a cron I have here: FULL OUTPUT: acoxxx Lastlogin= 2010/07/15 13:10 db2t Lastlogin= 2010/07/16 13:09 db2tadm Lastlogin= 2010/07/20 13:09 eisuser Lastlogin= 2010/07/20 11:53 israel Lastlogin= 2010/07/10 11:42 nmon Lastlogin= 2010/07/05 12:55 norbac Lastlogin=... (4 Replies)
Discussion started by: iga3725
4 Replies

4. Shell Programming and Scripting

Formatting output so I can calculate time difference between two stamps

I know there have been a million questions regarding calculating time stamps, and with enough googling, I think I'm almost there (I'm going to use the changing the times into seconds and subtracting solution). My problem is that I'm not sure how to format my log file to get the info I need. Below... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

5. Shell Programming and Scripting

Calculate P Value -Awk

Is there any awk command to calculate P Value ?(Probability) Is it possib;e to calculate P va;ue for this data for ex? 7.891284 8.148193 7.749575 7.958188 7.887702 7.714877 8.141548 7.51845 8.27736 7.929853 7.92456 8.249126 7.989113 8.012573 8.351206 (2 Replies)
Discussion started by: stateperl
2 Replies

6. Solaris

how we can calculate this bytes(55207936) in to MB(output=26957)

root@erpdevserver $ vxassist -g devdg maxsize Maximum volume size: 55207936 (26957Mb) This is the output in vxvm(3.1).. my question is how we can calculate this bytes(55207936) in to MB(output=26957) or in GB.plz tell how to calculate (2 Replies)
Discussion started by: tv.praveenkumar
2 Replies

7. Shell Programming and Scripting

awk script to calculate total

Hi First field is the Record Type. A Record Type 5 can have multiple Record Type 6's before another Record Type 5 appears. I want to calculate the total of fields at position 8-11 on Record type 6 when Record Type 5 has a field at position 11-14 equals to '2222'. then it should delete the lines... (2 Replies)
Discussion started by: appsguy616
2 Replies

8. Shell Programming and Scripting

how can i calculate a file using awk

hi all Am new to scripting... So,i have a file named file1 its contents are as follows: joy 55 66 77 ruby 77 88 99 saloni 88 44 33 I would require a script which will calculate its percentage,its total and the average with awk script Many thanks in advance.. Please reply me at... (4 Replies)
Discussion started by: whizkidash
4 Replies

9. Shell Programming and Scripting

calculate output

I was wondering can anyone give me a clue how to start script which would do the following: I have 2 numbers as input for example: 100 and 1000 and I need to create file and in that file should be written 100 - 199 200 - 299 300 - 399 400 - 499 500 - 599 600 - 699 700 - 799... (3 Replies)
Discussion started by: amon
3 Replies

10. Shell Programming and Scripting

How to calculate with awk

Hi, I have below awk statement and I need to convert the second field ( substr($0,8,6))from minutes to hours with 2 decimail place. How can I achieve this? /usr/bin/awk '{print substr($0,23,4),substr($0,8,6)}' /tmp/MANAGER_LIST.$$ >> /tmp/NEWMANAGER_LIST.$$ Thanks for any help! (4 Replies)
Discussion started by: whatisthis
4 Replies
Login or Register to Ask a Question