Loading
View RSS Feed

sachdev

Shell Script To Calculate log10(xi) Where xi Is A Series Of Numbers Stored In A File "data.txt"

Rate this Entry
Code:
b=10
sum=0
file=`cat data.txt`
for x in $file
do
y=` echo "scale=5; l($x)" | bc -l `
z=` echo "scale=5; l($b)" | bc -l `
lt=` echo "scale=5; ($y/$z)" | bc -l `
echo " log($x)=$lt "
sum=` echo "scale=5; ($sum+$lt)" | bc `
done
echo " The Sum:$sum "
output

Code:
[cs08130001045@FileServer ~]$ sh logarithm
log(1)=0
log(2)=.30102
log(3)=.47712
log(4)=.60205
log(5)=.69896
log(6)=.77814
log(7)=.84509
log(8)=.90309
log(9)=.95424
log(10)=1.00000
The Sum:6.55971
[cs08130001045@FileServer ~]$

Data.txt

1
2
3
4
5
6
7
8
9
10

Submit "Shell Script To Calculate log10(xi) Where xi Is A Series Of Numbers Stored In A File "data.txt"" to Digg Submit "Shell Script To Calculate log10(xi) Where xi Is A Series Of Numbers Stored In A File "data.txt"" to del.icio.us Submit "Shell Script To Calculate log10(xi) Where xi Is A Series Of Numbers Stored In A File "data.txt"" to StumbleUpon Submit "Shell Script To Calculate log10(xi) Where xi Is A Series Of Numbers Stored In A File "data.txt"" to Google

Updated 12-04-2011 at 07:03 PM by Harsh

Categories
Unix

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.