3 ms·
Sometimes I want to output specific files from a zip file to stdout. These programs can list the files in the archive, but I have never found an easy way to ex
by 1vuio0pswjnm7 4y ago
Sometimes I want to output specific files from a zip file to stdout.
These programs can list the files in the archive, but I have never found an easy way to extract specific files without having to type paths on the command line, or use a filelist (something like tar xf 1.tar -T list which zip utilities generally cannot do).
Until I am advised of something better, a quick and dirty solution:
usage: 1.sh 1.zip # displays list of files with line numbers
1.sh 1.zip 5p # extracts the file listed on line 5 to stdout
1.sh 1.zip 5,6p # extracts the files listed on lines 5 and 6 to stdout
1.sh 1.zip 5p\;8p # extracts the files listed on lines 5 and 8 to stdout
1.sh 1.zip /src/ # extracts the files with "src" in their path to stdout
case $# in :)
;;1)exec 7z l $1|sed -n '/^---/,/^---/{/^---/!p;}'|cat -n
;;2)
y=$1
shift
x=$(7z l $y|sed -n "/^---/,/^---/{/^---/d;s/.* //p;}"|sed -n "$@")
7z x -so $y $x
exec echo
;;0|*)exec echo usage: $0 zip-file \[sed cmd\]
esac;