Hey everyone, i need to write a script that accepts a file as an argument and then compresses this file with bzip2 gzip and zip. I'm trying to get the output to be a sorted table which displays the file size before compression and after compression for each compression program.
bzip2 174145 13976
gzip 174145 11746
zip 174145 11879
The code I have so far is listed below, however the output is an absolute mess and i've confused the hell out of myself!
Anyone able to help me?
Code:#!bin/sh arg="$1" # Get the original file size file_size=$(stat -c'%s' $arg) echo "$file_size" # Get sizes gzip=$(gzip -c "$arg" | wc -c) zip=$(zip -c "$arg" | wc -c) bzip2=$(bzip2 -c "$arg" | wc - c) # Unsorted output echo "gzip $file_size $gzip" >> output.txt echo "zip $file_size $zip" >> output.txt echo "bzip2 $file_size $bzip2" >> output.txt #sorted list sort -n -r +3 -4 output.txt > sorted.txt cat sorted.txt