Monday 15 September 2014

ubuntu - How to unzip files that have been zipped twice? -



ubuntu - How to unzip files that have been zipped twice? -

i've been given set of info files (csv) have been set folders, zipped, combined zip archive. how files out same directory, while ensuring don't end 2 files beingness created have same name?

for example,

data.zip

contains

20141015.zip 20141008.zip

20141015.zip contains directory, 20141015, has 2 files in it,

smith.csv jones.csv

20141008.zip contains directory, 20141008, has 2 more files in it, smith.csv , johnson.csv end 1 directory,

unzipped_data,

which contain

20141015-smith.csv 20141015-jones.csv 20141008-smith.csv 20141008-johnson.csv

this question shows me how unzip files in folders , set them corresponding folders, want files in 1 folder simplify farther operations, , have problem of 2 layers of zipping contend with, not one.

if understand needs, think script you. waiting comment. :)

instruction: create script.sh , re-create script in directory data.zip archive. script working name of archives , name of csv. create generalized script needs. if need please leave comment.

#!/bin/bash currloc="$pwd" path="${currloc}" cd ${currloc} #extract first archive in temp directory filename in $path/*; extension="${filename##*.}" if [ "${extension}" == 'zip' ]; unzip $filename -d $path/temp fi done count=0 filename in $path/temp/*; extension="${filename##*.}" #extract extension compair if archive or not name=${filename##*/} #extract name of zip file extension name=${name%.*} #extract name of zip file without extension if [ "${extension}" == 'zip' ]; ((count++)) unzip $filename -d $path/temp/$count file in $path/temp/$count/* ext="${file##*.}" if [ "${ext}" == 'csv' ]; csvfilename=${file##*/} mv $path/temp/$count/$csvfilename $path/$name-$csvfilename fi done fi done #remove temp directory rm -r $path/temp

ubuntu unzip

No comments:

Post a Comment