Trouble with Awk

Hi all,
I'm writing a program in bourne shell that compresses a file 3 different ways then displays a table of data with the compression type, original file size, compressed size and compression ratio. I've written most of it but reached 2 problems that won't allow me to finish it correctly.
The first is the equation for the ratio (compression ratio = ((original size - compressed size) / original size)*100)
doesn't work in a expr because of the brackets and such. I tried breaking it up into steps but it won't work. I was told to try using the awk command to do this but haven't been able to find anything on using the awk command to do such equations.:frowning:
My next problem is the table needs to be sorted so the biggest compression ratio is at the top so it'll look like this(made up numbers):

zip 334 80 68.3
gzip 334 110 54.5
bzip2 334 200 35.9

again I believe it is an awk command, using the awk field choosing to sort the lines by the $4 but I can't find use of sort in this way. So Far I have the 4 values put into a single value ie:

 bstats="bzip2 $unzipsize $bzsize $bzipratio" 

I tried putting these 3 values into a file with a > but I don't know how to then use that file in the program to sort and then display.
Any help on how to use awk these ways would be appriciated! :slight_smile:

echo `expr \( \(  334 - 80 \) \* 100 \/ 334 \) `
sort -nrk4 file

You should read the manual for expr and sort

Thanks for that. I shall try it.

---------- Post updated at 09:03 PM ---------- Previous update was at 08:06 PM ----------

Wow that was easy! I thought it would end up extremely complex. Thank you so much for your help! It works perfectly :slight_smile: