Shell Script - compression


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell Script - compression
# 1  
Old 09-04-2006
Shell Script - compression

Hello all, i am a complete beginner when it comes to unix and shell scripting.

I want to be able to compress a file (ff) with a shell script for example the command would look like

compress.sh ff

then with the script have the file compressed using the zip, gzip and compress commands.

I want to have the size of the file and the size of hte compressed file outputed to the screen with the three programs something like this

gzip 17375 5550 68.1
zip 17375 5665 67.4
compress 17375 7641 56.0

each of the values should be in columns also.

with the last column being the compression ratio. those numbers are just examples.

I'm having trouble storing the value of the filesize in a variable and also how to get the data displayed like I would like it above in columns.

I was thing of having the example stored to a file as then I can have the 3rd column sorted by the compression of the file.

Any help would be greatly appreciated in how to ge this done.

Cheers

Tony
# 2  
Old 09-04-2006
Quote:
Originally Posted by noodlesoup
I'm having trouble storing the value of the filesize in a variable and also how to get the data displayed like I would like it above in columns.
Use arrays to store the values (to get filesize you can use something like $size=`ls -l | awk '{print $5}'`). Look at http://www.tldp.org/LDP/abs/html/arrays.html

Quote:
Originally Posted by noodlesoup
I was thing of having the example stored to a file as then I can have the 3rd column sorted by the compression of the file.
Pipe your output through the sort

Quote:
Originally Posted by noodlesoup
each of the values should be in columns also.
Try '\t'
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Compression with openssl

Hi , 1-I need to know please if it's possible to compress using openssl? Here is the version used: openssl version -a OpenSSL 0.9.7d 17 Mar 2004 (+ security fixes for: CVE-2005-2969 CVE-2006-2937 CVE-2006-2940 CVE2006-3738 CVE-2006-4339 CVE-2006-4343 CVE-2007-5135 CVE-2008-5077... (3 Replies)
Discussion started by: Eman_in_forum
3 Replies

2. Linux

Best Compression technique ?

Hi all, I am working on a sample backup code, where i read the files per 7200 bytes and send it to server. Before sending to server, i compress each 7200 bytes using zlib compression algorithm using dictionary max length of 1.5 MB . I find zlib is slow. Can anyone recommend me a... (3 Replies)
Discussion started by: selvarajvss
3 Replies

3. Shell Programming and Scripting

file compression

I'am looking for script (or tool) that would compress all files with given extension in all subdirectory. Important part is that every one file have to end in separate archive whit it's own name. Eaven if I could point multiple file in one directory and compress them it would be ok. I' am... (1 Reply)
Discussion started by: Demerzel
1 Replies

4. Shell Programming and Scripting

Folder compression

Hi Guys, totally new to scripting. I have a huge list of foleders. I want to tar the contents of each folder inside the same folder and the name of the tar file is the same name as the folder. how would I go about this in scirpt? cheers Viper (3 Replies)
Discussion started by: brownviper1966
3 Replies

5. UNIX for Dummies Questions & Answers

Compression and decompression in the same script

Hi Guys, I'm just wondering how to compress and decompress a file in the same script using multiple programs, and can it be done in one line? e.g gzip file && gunzip file bzip2 file && bunzip file I tried this and a few other combinations but it doesn't seem to work. Any... (6 Replies)
Discussion started by: Spaulds
6 Replies

6. UNIX for Dummies Questions & Answers

.z file compression

Hello, I have a .z file which i understand to be UNIX. I'm on PC (no UNIX boxes) and have tried many different unzipping programs to extract this .z file, but only PicoZip has allowed me to view what is inside (telling me, i think, that it's not corrupt), but i have not been able to extract... (3 Replies)
Discussion started by: Gonecat
3 Replies

7. UNIX for Advanced & Expert Users

Predictor compression

Hi everybody, Does anybody know,whether linux-2.4.20-8 supports predictor1 compression in PPP protocol support,as i was able to see there were only two compression techniques that r being supported i.e bsd and deflate compression from "make menuconfig" under network device... (0 Replies)
Discussion started by: sriram.ec
0 Replies

8. Shell Programming and Scripting

finding compression ratio in Bourne shell

in the instance of a file compressed with compress to a .Z extension... how would I, in the Bourne Shell, capture its compression ratio? Gunzip returns -1 and I'd then gone down the track of roughly calculating the ratio (not including time) manually. Until I found out the Bourne Shell... (7 Replies)
Discussion started by: nortypig
7 Replies

9. UNIX for Dummies Questions & Answers

.bz2 compression

I have heard that bz2 compression a relatively new compression encoding algorithm, far superior to tar and gz. I also remember that I downloaded a FreeBSD LiveCD a while back that was only a couple hundred megs instead of the usual 650ish using bz2 - big difference, I'd say. But to the point, what... (4 Replies)
Discussion started by: Phobos
4 Replies

10. UNIX for Dummies Questions & Answers

compression utilities

I've noticed bzip2 gives a little bit better compression than gzip. So...I'm curious...what's gives the best compression out of all the compression utilities? Thanks! (6 Replies)
Discussion started by: jalburger
6 Replies
Login or Register to Ask a Question