Tuesday, September 22, 2009

Reading a txt file in a Zip

A problem came up...to read a text file without extracting the file from the zip file.
So it was like this how i went by it:

1] Zip file was present in my home dir by the name 'archive.zip',so listing the file in home directory was done by.

[sawrubt@sawrub ~]#
[sawrub@sawrub ~]# ll archive.zip
-- output deprecated --
[sawrub@sawrub ~]#
2] List the files present in that archive.
[sawrub@sawrub ~]# unzip -l archive.zip|tail
-- output deprecated --
9999770 09-02-09 12:09 00010b32.jdb
9999963 09-02-09 12:09 00010b33.jdb
6371421 09-11-09 11:36 00010b34.jdb
71 09-11-09 11:49 version.txt
-------- -------
628281884 504 files
[sawrub@sawrub ~]#
3] And now my task was I had to read version.txt, so went by firing in the command
[sawrub@sawrub ~]# unzip -p archive.zip version.txt
-- output deprecated --
[sawrub@sawrub ~]#
and all was done.
Definition of '-p' option per unix manual:
-p extract files to pipe (stdout).Nothing but the file data is sent to stdout, and the files are
always extracted in binary format, just as they are stored (no conversions).


Cheers.

0 comments:

Post a Comment