nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Help with numbers

This is a discussion on Help with numbers within the Shell scripting forums, part of the Development/Scripting category; Hi All, I am back after a long time. And I have a problem I am writing a script and ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 12-12-2006, 11:29 AM
Member
User
 
Join Date: Jul 2005
Posts: 85
Rep Power: 0
ricc
Default Help with numbers

Hi All,

I am back after a long time. And I have a problem

I am writing a script and got stuck with some numbers. The out put of one of the commands gives me this:

22.00
23.00
23.00
21.00
.
.
.
.
so on & so forth

What I need is to take the numbers and get an average of all these. The result will be used as an input for test condition.

The number of rows can increase or decrease. But at present it is 10.

Please help me.

Thanks,

ricc
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-12-2006, 03:20 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Following code is easy to follow
Code:
#!/bin/bash
INPUT="data.txt"
TOTAL=$(cat $INPUT | wc -l)
out=0
n=0
for n in $(cat $INPUT)
do
 out="$out + $n"
done
echo -n "Avg is : " 
echo "( $out ) / $TOTAL" | bc
echo ""
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
  #3 (permalink)  
Old 12-12-2006, 04:09 PM
Member
User
 
Join Date: Jul 2005
Posts: 85
Rep Power: 0
ricc
Default

Thanks Vivek.

I still have a lot to learn.

ricc
Reply With Quote
  #4 (permalink)  
Old 12-16-2006, 07:48 PM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,036
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

NP, remember practice makes a man perfect so keep coding...
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

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

Similar Threads

Thread Thread Starter Forum Replies Last Post
How to check CPU Numbers in Linux raj Linux hardware 1 06-17-2008 03:29 PM
pattern search with numbers mercuryshipz Coding in General 0 02-15-2008 12:16 AM
Use float real numbers in a shell script hao Shell scripting 1 03-16-2007 02:35 AM
script to add all numbers from 1 to 100 ricc Shell scripting 3 08-17-2005 03:27 PM


All times are GMT +5.5. The time now is 09:11 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36