Home > bash > 7z – How to read files without uncompressing.

7z – How to read files without uncompressing.

Is there a way to read 7z files without uncompressing them.

I am thinking in the lines of zcat, zless, zgrep and bzcat, bzless etc.

I have some 7z files and I have been forced to do something like

#!/bin/bash
for file in *.7z;
do
    # uncompress
    7z e "$file";
    # The files are compressed mysqldump files.
    # compress again
    gzip *.sql;
done

And then I use zcat et al to get my data.

Update:
I was forced to write out my own version of 7zcat and 7zless that lets me read files without uncompressing. More on that here Writing 7zcat and here Writing 7zless

Updated(2011-10-07):
I just learnt that the for loop above will not handle spaces in files (Added quotes round “$file”). Alternative ways of doing the same is here

http://www.commandlinefu.com/commands/view/4640/extract-all-7zip-files-in-current-directory-taking-filename-spaces-into-account

Advertisements
Categories: bash Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s