finding compression ratio in Bourne shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding compression ratio in Bourne shell
# 1  
Old 08-24-2006
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 doesn't do calculations!

So I am perplexed. I am stuck in the Bourne Shell, I'm not permitted to use anything else - what function returns the compression ratio in a manner I can capture.

There was one process with a -v verbose option but it would not pipe to echo or > to a file from memory.

Strategically stuck is the phrase. Smilie
# 2  
Old 08-24-2006
wow I'm using the UNIX bc calculator within bourne which to me is a pretty cool way to get away with not leaving and still doing calculations lol...

but if anyone gets a better idea how to grab the 'real' compression ratio for a .Z file I'd greatly appreciate the insight.

thanks Smilie

wow - the bc calculator!
# 3  
Old 08-24-2006
Try..
Code:
set $(gzip -v file.txt 2>&1)
echo $2

# 4  
Old 08-24-2006
hi Igor, thanks but it gives me a syntax error

syntax error: '(' unexpected
# 5  
Old 08-24-2006
could you recommend a good quality tutorial page on the uses of set - I don't really see much sense in the man pages for this one...

a tutorial with generalised examples would make it clearer

i understand set on itself has all of he name=value pairs for my environment but beyond that I think I need to do some reading.

thanks Smilie
# 6  
Old 08-24-2006
could someone explain with set why this isn't possible?

Code:
set `compress -v fileX` > fileY.txt

# 7  
Old 08-24-2006
I am clearly missing something here.
Suppose you have a compressed file with name = file.Z. The compression ratio is the number of bytes in the original divided by the number of bytes in the compressed file.


Code:
oldsize=`zcat file.Z | wc -l`
newsize=`ls -l file.Z | awk '{print $4}' `
comp_ratio=`echo $oldsize / $newsize | bc -l`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies

2. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

3. Shell Programming and Scripting

Bourne/C shell help

Exercise Five Write a Bourne shell script which: • Professionalism: plan for this from the start. • Has one command line argument. • If the command line argument is a directory then the script should output the number of files in the directory. • If the command line argument is an ordinary... (2 Replies)
Discussion started by: moesom
2 Replies

4. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

5. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done. I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies

6. UNIX for Dummies Questions & Answers

Bourne-again shell

Hi guys !! well i'm still new in learning UNIX , and actually i'm still studying it by myself .. anyway, some people told me the Bourne-again shell is a good version of UNIX to work on , and i tried to download yesterday but i didn't know how to start it ...... the ReadMe file associated with... (3 Replies)
Discussion started by: mrsamer
3 Replies

7. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: noodlesoup
1 Replies

8. Shell Programming and Scripting

bourne shell programming help

hey, i have 2 files... orders and products how do i do calculations on the order using the products ? say if the products file is: a123:shirt:10.00 zz123:nice shirt:19.95 and the order file is: 05/08/30 a123 10 zz123 3 Jun-3-1994 a123 2 2005.06.23 a123 2 (1 Reply)
Discussion started by: ganjakh0r
1 Replies

9. Shell Programming and Scripting

Bourne Shell and Arrays

Hi everyone, first post here so please be gentle :-) I normally likle to script in Bourne Shell simply for guarenteed compatibility across any system I might run across but this latest problem has me stumped. Arrays is a rather significant construct missing from sh and after finding a way to... (2 Replies)
Discussion started by: Unbeliever
2 Replies

10. UNIX for Dummies Questions & Answers

Bourne Shell Script

Hello, I'm throwing this out there as a novice to the Unix world...I've been working on a project that requires me to ouput (using the echo command) a list of names in a single column format, but the problem is the input is in row format followed by a blank space...If anyone could give me a... (2 Replies)
Discussion started by: dmhonor914
2 Replies
Login or Register to Ask a Question