Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

UNIX PROGRAMMING HELP!! I have a programming. assignment that will take a FILENAME. on the COMMAND. LINE. as its argument. If not File. Name. is.

UNIX PROGRAMMING HELP!!

I have a programming. assignment that will take a FILENAME. on the COMMAND. LINE. as its argument.

If not File. Name. is. Provided., Print an error. message and exit.

The Script. should. compress the file with: -gzip, -bzip2, and -zip. At each stage, gather the size of the file before and after ,compression.

Then display a report. showing: The .Compression Program., .Uncompressed Size, .Compressed Size, and. Compression. Ratio(.up to. one decimal Point).

I created a test.txt file to test it, and I am geting this OUTPUT:

$ sh Program2.sh test.txt .Program2.sh: line 33: bc: .command not found .Program2.sh: line 41: bc: .command not found .Program2.sh: line 45: zip: .command not found .Program2.sh: line 49: bc: .command not found Report: Compression Program Uncompressed size Compressed size Compression Ratio bzip2 52428800 81 gzip 52428800 50913 zip 52428800 0

Am I doing something wrong? Or is my code incorrect? Can you help me meet the following requirements?

Below is my Code: ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#!/bin/bash

# if condition to handle:

# 1. argument is not there

# 2. argument is not equal to 1

if [ "$#" -eq 0 ]; then

echo "ERROR: Please provide a file to compress!"

exit

elif [ "$#" -ne 1 ]; then

echo "ERROR: Please play with one file at a time!"

exit

fi

# Calculating actual size of file

actualsize=$(wc -c <"$1")

# Calculating gzip compressed file and its compression ratio

gzip < $1 > $1.gz

gzipsize=$(wc -c <"$1.gz")

gzipcr=$(echo "scale=1; $actualsize/$gzipsize" | bc)

# Calculating bzip compressed file and its compression ratio

bzip2 < $1 > $1.bz2

bzipsize=$(wc -c <"$1.bz2")

bzipcr=$(echo "scale=1; $actualsize/$bzipsize" | bc)

# Calculating zip compressed file and its compression ratio

zip < $1 > $1.zip

zipsize=$(wc -c <"$1.zip")

zipcr=$(echo "scale=1; $actualsize/$zipsize" | bc)

# Tip: above written scale=1 indicates decimal upto one place

# Report generated in row column format

printf "Report: "

printf "Compression Program \t Uncompressed size \t Compressed size \t Compression Ratio "

printf "\t bzip2 \t\t $actualsize \t\t $bzipsize \t\t\t $bzipcr "

printf "\t gzip\t\t $actualsize \t\t $gzipsize \t\t\t $gzipcr "

printf "\t zip \t\t $actualsize \t\t $zipsize \t\t\t $zipcr "

# Tip: Higher the compression ratio, smallest will be the compressed file size. Because, bzip2 is the best compression type than gzip than zip.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

The role of life: It consists of your own service to yourself.

Answered: 1 week ago