How can i calculate percentage ??

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 help me to resolve this issue.

Code answer was:

echo "scale=2; $lp_count*100/$num_reads" | bc
99.93

or for you

echo "scale=2; $equal.dat*100/$total.dat" | bc

Hi joeyg

Thanks for the reply...

I excuted the same command in my shell script am getting error like
syntax at error line 1

echo "scale=2; $equal.dat*100/$total.dat" | bc

Please advice me.

try this

> equal_dat=14
> total_dat=18
> echo "scale=2; $equal_dat*100/$total_dat" | bc
77.77
>

am using the HP-unix ,does this support this format??
not_equal=12
equal_dat=14
total_dat=18

i tried for equal and not eqaul as well.

For equal..i didn't got any answer
echo "scale=2; equal_dat*100/total_dat" | bc

for not equal i got a an error like
echo "scale=2; not_equal_count.dat*100/total_count.dat" | bc
syntax error on line 1,

Please advice

Try the first approach in steps
echo equal_dat
then
echo equal_dat*100 | bc
and so on

For the second, you used a variable with a . in its name

(While I used HP-UX in past, don't have a way to try out where I am currently sitting.)

echo equal_dat

it's only echo the file name like equal_dat not the content of the equal_dat.