Gzip reader


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gzip reader
# 1  
Old 04-18-2012
Gzip reader

Hi ,
I have gzip file.
Is it possible to script a code which can read from compressed byte offset to uncompressed byte length?


Regards,
Chetan.C
# 2  
Old 04-18-2012
You mean, translate an offset in the gzip file to an offset in the unzipped file?

It may not always make sense to do so. These things aren't necessarily related so directly. Longer sequences than bytes may be necessary to encode things.
# 3  
Old 04-18-2012
One thing you could do, I suppose, is something like

Code:
dd if=file.gz bs=numofbytes count=1 | gunzip 2>/dev/null | wc -c

That would break the zip file early, and show how many bytes it managed to decode before it broke. The 2> /dev/null is necessary because gzip would certainly complain.
# 4  
Old 04-19-2012
Hi,
Thanks for ther response.
Would like to add more information to the question.

The gzip file that im creating is by zipping individual stream of data through datastage.
I am calculating the compressed byte length from another copy of the file which is not zipped by the below code.
Code:
while IFS="^" read FIELD1 FIELD2
do
        echo "$FIELD2"
        echo "$FIELD1" | gzip | wc -c
done<"$file"

Field2 is the filename of the record.

I'm expecting that compressed size of 1st record should be the byte offset of second record in the zipped file.

Am i right in thinking so?

Thanks.
# 5  
Old 04-19-2012
Sorry, no.

gzip doesn't work that way. You can't really seek inside a gz file, for starters, because you can't use a partial file -- any of the bytes are meaningless without the others. And one byte can represent many bytes -- kind of the whole point of using it. So there's no longer any direct, easy, accurate correlation, and not even any benefit in finding out the rough location.

Last edited by Corona688; 04-19-2012 at 10:52 AM..
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 04-23-2012
Hi,

Firstly apologies for that double post!.
Thanks for the responses.Will ensure it does not happen.

Thanks,
Chetan.C
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

gzip vs pipe gzip: produce different file size

Hi All, I have a random test file: test.txt, size: 146 $ ll test.txt $ 146 test.txt Take 1: $ cat test.txt | gzip > test.txt.gz $ ll test.txt.gz $ 124 test.txt.gz Take 2: $ gzip test.txt $ ll test.txt.gz $ 133 test.txt.gz As you can see, gzipping a file and piping into gzip... (1 Reply)
Discussion started by: hanfresco
1 Replies

2. Solaris

Serial Barcode Reader

I have a serial barcode reader which I attached to my Solaris 10 workstation. I can see the barcode scanned data appearing when I do a tip hardwire. Question is how can I enable the data to appear in command prompt or any text editor programs? Thanks for the help (3 Replies)
Discussion started by: timtan169
3 Replies

3. OS X (Apple)

Yasr screen reader

Hello, I own a MacBook pro laptop running mac os x 10.5.7 I recently downloaded yasr which is a screen reader program. I want to use yasr at the command line. I have a file which is in my home directory in a folder called downloads the file is called: yasr-0.6.9.tar I looked up on google the... (2 Replies)
Discussion started by: jamesapp
2 Replies

4. AIX

pdf reader

which package is to be installed to view pdf files in AIX machine? i already have xpdf version 1...but, some pdf files are not opening in it.help me out. (1 Reply)
Discussion started by: me.kamph
1 Replies

5. Solaris

Secure Card Reader

I see on some of the recent Sun workstations that there is a secure card reader installed. I have a Sunblade 100 and 150 and would like to know, how do you access this device or turn it on to use it? Thanks, (2 Replies)
Discussion started by: stocksj
2 Replies

6. News, Links, Events and Announcements

source reader tool

Hi, can anybody give info on source reader tool?which platform does it wok on?and how it works (1 Reply)
Discussion started by: vijaya2006
1 Replies

7. UNIX for Advanced & Expert Users

source reader info

Hi friends, I urgently need to know if there is any tool called source reader in C or Unix or Linux...... If so ..plz let me know the details.I am running out of time..... (0 Replies)
Discussion started by: vijaya2006
0 Replies

8. UNIX Desktop Questions & Answers

NewsGroup Reader . . . Need Advice

I recently installed Suse 8.0 and am in need of a dependable news group reader. I need something that will authenticate just like Outlook Express does, because I will connecting to an Exchange News Host. Does anyone have any suggestions as to what I should donwload for a Microsoft compatible news... (2 Replies)
Discussion started by: pc9456
2 Replies

9. UNIX for Dummies Questions & Answers

postscript reader for hp-unix

sorry, it is a dumb question, but i could not find any answer in anything else. does anybody know whether there is any postscript file reader for HP-Unix? :) (1 Reply)
Discussion started by: sskb
1 Replies

10. UNIX for Dummies Questions & Answers

Need Wtmp Reader

I would loke to read the WTMP file. This is a binary file in the /var/logs directory. Is there any utility which will convert this binary file to ASCII format? (1 Reply)
Discussion started by: pgold1
1 Replies
Login or Register to Ask a Question