04-11-2013
Quote:
Originally Posted by
Aditya.Gurgaon
i tried it :
z=$(echo "scale=4 ; ($x/$y*100)" | bc)
bt it is giving result : 33.3300
x=1
y=3
i want 33.33
That's because you set scale to '4' which is the number of digits right of the decimal point... So leave scale to '2' and it should work.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi, I am new to awk.. and getting used to the scripts. I have a small data set 5 coulms.. 16 rows.
1) I am trying to remove the percentages of each line of colum 3..like first line divided the sum of colum 3 divided by 100 and print it out. removing hte percentages of each line
I would really... (3 Replies)
Discussion started by: rockiefx
3 Replies
2. Shell Programming and Scripting
how would you calculate percentage by per line? Given a column of 16 lines, grab each line and divide it by the sum of the entire column and multiply by 100?
thanks ... (8 Replies)
Discussion started by: rockiefx
8 Replies
3. Shell Programming and Scripting
i have 3 files like
total.dat=18
equal.dat=14
notequal.dat=16
i need find the equal percentange means:
equalpercentage = ($equal.dat / $total.dat * 100)
How i can do this ?
I tried some of the answers to calculate the percentage in this forums.but it couldn't worked.Some one please... (6 Replies)
Discussion started by: bobprabhu
6 Replies
4. UNIX for Dummies Questions & Answers
How to calculate percentage of two values in unix. (5 Replies)
Discussion started by: venkatesht
5 Replies
5. Shell Programming and Scripting
Hi all
i have a text file with columns delimited with ,
2010-08-18,10,24,.09751,39,7,14872,26732
.
.
.
i would to add a extra column in the end with percentage calculation of columns 5 and 8 ie (39/26732)*100
so the output must look like
... (6 Replies)
Discussion started by: posner
6 Replies
6. Shell Programming and Scripting
Hi,
I have two variable and I need to calculate the percentage of them.
Example:
(b-a)*100/b
How can I do it? I need to do it till 2 decimal point. (16 Replies)
Discussion started by: Anupam_Halder
16 Replies
7. Shell Programming and Scripting
Hi,
I am looking for generic commands / scripts that could run across platforms especially on HP Itanium boxes to give me % of free OS parameters
For eg:
Free Total Memory RAM : 20 %
Free Total Swap Memory: 35%
Free Total CPU utilisation: 44%
Free Disk Space: /appl = 55%... (5 Replies)
Discussion started by: mohtashims
5 Replies
8. Shell Programming and Scripting
Hello,
Ive got a bunch of numbers here e.g:
6065
6094
6348
6297
6161
6377
6338
6290
How do I find out if there is a difference between 10% or more between one of these numbers ? I am trying to do this in Bash.. but no luck so far.. Does anyone have an Idea ??
Thanx,
- Pascal... (9 Replies)
Discussion started by: denbekker
9 Replies
9. Shell Programming and Scripting
Hi,
I have a text file in below format.
I trying to find a solution for finding percentage used for each of the NAMEs.
Directory ALLOCATED USED
NAME1 93MB 93KB
NAME2 25G 62K
NAME3 14G 873M
NAME4 25G 62K
NAME5 20G... (10 Replies)
Discussion started by: ctrld
10 Replies
10. Shell Programming and Scripting
i have a file say test with the below mentioned details
Folder Name Total space Space used
/test/test1 500.1GB 112.0 GB
/test/test2 3.2 TB 5TB
/test/test3 3TB 100GB
i need to calculate percentage of each row based on total space and space used and copy... (9 Replies)
Discussion started by: venkitesh
9 Replies
BC(1) General Commands Manual BC(1)
NAME
bc - arbitrary-precision arithmetic language
SYNOPSIS
bc [ -c ] [ -l ] [ file ... ]
DESCRIPTION
Bc is an interactive processor for a language that resembles C but provides arithmetic on numbers of arbitrary length with up to 100 digits
right of the decimal point. It takes input from any files given, then reads the standard input. The -l argument stands for the name of an
arbitrary precision math library. The following syntax for bc programs is like that of C; L means letter a-z, E means expression, S means
statement.
Lexical
comments are enclosed in /* */
newlines end statements
Names
simple variables: L
array elements: L[E]
The words ibase, obase, and scale
Other operands
arbitrarily long numbers with optional sign and decimal point.
(E)
sqrt(E)
length(E)
number of significant decimal digits
scale(E)
number of digits right of decimal point
L(E,...,E)
function call
Operators
+ - * / % ^ (% is remainder; ^ is power)
++ --
== <= >= != < >
= += -= *= /= %= ^=
Statements
E
{ S ; ... ; S }
print E
if ( E ) S
while ( E ) S
for ( E ; E ; E ) S
null statement
break
quit
"text"
Function definitions
define L ( L , ... , L ){
auto L , ... , L
S ; ... ; S
return E
}
Functions in
-l math library
s(x) sine
c(x) cosine
e(x) exponential
l(x) log
a(x) arctangent
j(n, x)
Bessel function
All function arguments are passed by value.
The value of an expression at the top level is printed unless the main operator is an assignment. Text in quotes, which may include new-
lines, is also printed. Either semicolons or newlines may separate statements. Assignment to scale influences the number of digits to be
retained on arithmetic operations in the manner of dc(1). Assignments to ibase or obase set the input and output number radix respec-
tively.
The same letter may be used as an array, a function, and a simple variable simultaneously. All variables are global to the program. Auto-
matic variables are pushed down during function calls. In a declaration of an array as a function argument or automatic variable empty
square brackets must follow the array name.
Bc is actually a preprocessor for dc(1), which it invokes automatically, unless the -c (compile only) option is present. In this case the
dc input is sent to the standard output instead.
EXAMPLE
Define a function to compute an approximate value of the exponential. Use it to print 10 values. (The exponential function in the library
gives better answers.)
scale = 20
define e(x) {
auto a, b, c, i, s
a = 1
b = 1
s = 1
for(i=1; 1; i++) {
a *= x
b *= i
c = a/b
if(c == 0) return s
s += c
}
}
for(i=1; i<=10; i++) print e(i)
FILES
/sys/lib/bclib mathematical library
SOURCE
/sys/src/cmd/bc.y
SEE ALSO
dc(1), hoc(1)
BUGS
No or operators.
A statement must have all three
A is interpreted when read, not when executed.
BC(1)