The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 find the number of files harish409 UNIX for Dummies Questions & Answers 5 10-09-2007 09:09 AM
Script to move certain number of files every 10 minutes. amitsayshii UNIX for Dummies Questions & Answers 1 02-26-2007 04:55 AM
awk script to find the number of files uni_ajay_r Shell Programming and Scripting 4 10-31-2006 06:58 PM
Script to generate Average Values gagan.delouri Shell Programming and Scripting 5 05-03-2006 05:29 AM
How to find no of occurances Finding average time? redlotus72 UNIX Desktop for Dummies Questions & Answers 1 02-21-2005 03:22 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-27-2008
bbbngowc bbbngowc is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 194
script to find the average number or files?

Anyone has a script or command in UNIX that can take 4 to five different numbers and calculate the average?
  #2 (permalink)  
Old 03-27-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
As it happens, I just wrote one.

Code:
vnix$ cat ~/bin/avg
#!/usr/bin/perl -lan

my $sum = 0.0;
map { $sum += $_ } grep { /^(\d+(\.\d+)?|\.\d+)$/ } @F;
print "$0: $sum / ", scalar (@F), " = ", $sum / @F if @F;
You'd type in numbers separated by space and hit enter when you're done.

Last edited by era; 03-27-2008 at 12:36 PM.. Reason: Usage instructions
  #3 (permalink)  
Old 03-27-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,509
Quote:
Originally Posted by bbbngowc View Post
Anyone has a script or command in UNIX that can take 4 to five different numbers and calculate the average?
Code:
# echo "1 2 3 4 6" | awk '{for(i=1;i<=NF;i++) t+=$i}END{print t/NF}'
3.2
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 05:33 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