how to see the content of a particular file in .tar.gz archive without unzipping the contents?
for ex abc.tar.gz has
abc/file1.txt
ab开发者_JAVA技巧c/file2.txt abc/abc1/file3.txt abc/abc2/file4.txti need to read/display the contents of file3.txt without extracting the file.
Thanks for any input.
import tarfile
spam = tarfile.open( "abc.tar.gz" )
if "abc/abc1/file3.txt" in spam.getnames():
with spam.extractfile( "abc/abc1/file3.txt" ) as ham:
print ham.read()
See tarfile.
tar -xzf mytar.tar.gz --to-command=cat filename.in.archive
精彩评论