V
V
VN2022-02-06 21:36:18
bash
VN, 2022-02-06 21:36:18

How to compare two files by percentage?

There are two files, one original, the other after compression.

somefile.pdf - 10.4 MB
somefile_compess.pdf  - 3.9 MB

How, using bash, to get what percentage of the file somefile_compess.pdf is compressed ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2022-02-06
@saboteur_kiev

Bash itself does not work with fractional numbers, and bc has scale=0 by default.
Write scale=1 in your script to get tenths of a percent, for example
bc -l <<< "scale=1;$full*$first/$second"

R
rPman, 2022-02-06
@rPman

3.9mb from 10.4mb is 100%*3.9/10.4=37.5%

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question