The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to set guest static IP satimis Ubuntu 3 08-02-2008 11:27 PM
Static Route Arun.Kakarla UNIX for Dummies Questions & Answers 2 07-17-2008 09:07 AM
static route ? chaandana IP Networking 3 07-05-2005 03:05 AM
Static wojtyla High Level Programming 6 02-25-2005 11:57 AM
Static IP google IP Networking 7 05-18-2003 08:33 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-22-2009
yanglei_fage yanglei_fage is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 25
How to static the average value

Hi all,

Sorry I make a mistake,the title should be "How to statistic the average value "

I do five times about "mv 123 to 456"
and do five times about "mv 456 to 123"
As we know,"time" can get the real usr sys value,
I want to get the average real,usr,sys of "mv 123 to 456" and "mv 456 to 123"


Quote:
#!/bin/bash
for ((i=1;i<=10;i+=1));do
echo "mv 123 to 456 the $i \n"
time mv 123 456;
echo "mv 456 to 123 the $i \n"
time mv 456 123;
done

I named it "test"

leiyang@leiyang-laptop:~$ ./test
mv 123 to 456 the 1 \n
real 0m0.005s
user 0m0.004s
sys 0m0.000s
mv 456 to 123 the 1 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 123 to 456 the 2 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 456 to 123 the 2 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 123 to 456 the 3 \n
real 0m0.008s
user 0m0.000s
sys 0m0.004s
mv 456 to 123 the 3 \n
real 0m0.005s
user 0m0.000s
sys 0m0.008s
mv 123 to 456 the 4 \n
real 0m0.004s
user 0m0.000s
sys 0m0.004s
mv 456 to 123 the 4 \n
real 0m0.002s
user 0m0.000s
sys 0m0.004s
mv 123 to 456 the 5 \n
real 0m0.002s
user 0m0.000s
sys 0m0.000s
mv 456 to 123 the 5 \n
real 0m0.002s
user 0m0.000s
sys 0m0.000s
for example :
for "mv 123 to 456"
I want to got real_average_123_to_456=(real+real+real+real+real)/5 (here real is for "mv 123 to 456'' in each time),also want to get usr_average_123_to_456,sys_average_123_to_456

for "mv 456 to 123"
I want to got real_average_456_to_123=(real+real+real+real+real)/5 (here real is for "mv 456 to 123'' in each time),also want to get usr_average_456_to_123,sys_average_456_to_123

how can I modify above code.I'm poor in bash shell.please show me a light

Last edited by yanglei_fage; 04-22-2009 at 01:54 PM..
  #2 (permalink)  
Old 04-22-2009
kodak kodak is offline
Registered User
  
 

Join Date: Jun 2003
Posts: 51
bash does not do floating point math by itself. Since you have to convert the output of time into something you can do math on, this whole thing scream "use perl" to me.

As a hint, though, look at your man page for time. On Linux you can do "time -p" and it will output in a decimal value instead of tacking on the minute and second units.
  #3 (permalink)  
Old 04-22-2009
colemar colemar is offline
Registered User
  
 

Join Date: Apr 2009
Location: Trento, Italy
Posts: 116
Quote:
Originally Posted by kodak View Post
bash does not do floating point math by itself
But apparently ksh does:

Code:
colemar@deb:~$ echo $((1.0/7))
bash: 1.0/7: syntax error: invalid arithmetic operator (error token is ".0/7")
colemar@deb:~$ ksh
$ echo $((1.0/7))
0.142857142857142857

  #4 (permalink)  
Old 04-22-2009
kodak kodak is offline
Registered User
  
 

Join Date: Jun 2003
Posts: 51
hah, sweet. I never use ksh, thanks.
  #5 (permalink)  
Old 04-23-2009
yanglei_fage yanglei_fage is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 25
Thanks for the reply, If we use ksh, How can we got the answer.
Anyone can post the code?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0