Results 1 to 2 of 2

Thread: Compressing argument files

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Question Compressing argument files

    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.

    e.g. output:

    File: ff
    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?
    Regards

    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

  2. #2
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    486
    Thanks
    10
    Thanked 50 Times in 47 Posts
    Rep Power
    8

    Default

    Hi,
    i think you need to use printf instead of echo
    see following examples :
    PHP Code:
    #!bin/sh


    arg="$1"


    # Get the original file size
    file_size=$(stat -c'%s' $arg)
    #echo "$file_size"


    # Get sizes
    gzip=$(zcat -"$argwc -c)
    # zip=$(zip -c "$arg" | wc -c)
    bzip2=$(bzip2 -"$argwc -c)

    header="\n %-10s\t%8s\t %10s\t%11s\n"
    format=" %-10s\t%08d\t%10s\n"
    width=43
    printf 
    "%$width.${width}s\n" "$divider"


    # Unsorted output
    printf "$header"  "TOOL" "FILE_SIZE" "COMPRESS_SIZE" >> output.txt
    echo "=========================================="
    # printf "$format"  "gzip $file_size $gzip"
    printf "$format"   "gzip"  "$file_size" "$gzip>> output.txt
    # printf "$format"  "zip $file_size $zip" >> output.txt
    printf "$format"  "bzip2" "$file_size" "$bzip2>> output.txt


    #sorted list
    # sort -n -r +3 -4 output.txt > sorted.txt
    # cat sorted.txt
    cat output.txt 
    i commented this " zip -c "$arg" | wc -c" because this command not working properly
    Rahul Patil <http://www.linuxian.com>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [Solved] iptables: Bad argument `pkttype'
    By valerio in forum Networking, Firewalls and Security
    Replies: 8
    Last Post: 19th October 2010, 05:26 PM
  2. Replies: 1
    Last Post: 4th September 2009, 01:02 PM
  3. [Solved] Argument for shell scripts
    By vampire in forum Shell scripting
    Replies: 2
    Last Post: 13th July 2009, 06:56 PM
  4. [Solved] Argument list too long
    By jerry in forum Linux software
    Replies: 2
    Last Post: 10th July 2009, 12:08 AM
  5. Argument list too long
    By raj in forum Shell scripting
    Replies: 1
    Last Post: 4th November 2008, 11:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •