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.
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!