Help with creating recursive unzip script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with creating recursive unzip script
# 1  
Old 09-08-2012
Help with creating recursive unzip script

Hello. I am trying to create a script that recursively looks at my folder structure, and extracts any .7z files that have not already been extracted yet. I know that all .7z files only have a single .txt file in them, and the only .txt file in any directory would be from that .7z file.

I am using 7-zip to extract all of the .7z files.

Here is an example directory structure.

Code:
./Folder/
./Folder/Subfolder 1/file A.7z
./Folder/Subfolder 1/file A.txt
./Folder/Subfolder 2/file B.7z

In this example, you can see that within Subfolder 2, the .7z file has not been unzipped, while it has within Subfolder 1. The Folder names and 7z names are variable, along with the depth of the directories.

Here's what I have so far, but I think I'm on the wrong track. So far I have a script that lists all folders that include a .7z file, but I can't figure out the rest. If you have a more efficient solution, I am completely open to it.

Code:
find . -type d | while read FOLDER
	do
		if ls -A "$FOLDER" | grep .7z > /dev/null
		then
			echo "$FOLDER"
		fi
	done

Any thoughts??
# 2  
Old 09-08-2012
Try something this..

Code:
find /pathname/ -type f -name *.7z | while read folder
do 
echo $folder
done

# 3  
Old 09-08-2012
Pamu - That gets me about halfway where I want to be. This is definitely more efficient, so thanks!

The goal is to look into each folder with a .7z file. If that folder with the .7z also includes a .txt file, skip it. If it does not, then unzip the .7z file (which only includes a single .txt file) into that same folder.
# 4  
Old 09-08-2012
Try something this...

Code:
find /pathname/ -type f -name *.7z |  while read folder
do 
fold_path=$(echo "$folder" | awk -F "/" '{$NF=""}1' OFS=/ )    #Get the folder path which has .gz files.

if [[ -e "$fold_path*.txt" ]]   #here we check for the presence of .txt files
then
echo ".txt file is present"
else
echo "do your unzip operations" #add your unzip code for $folder - which .gz file
fi
done

I hope this helps you...Smilie
This User Gave Thanks to pamu For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unzip the .zip file without using unzip utility in UNIX

I have .zip file, i want to list all the files archived in the zip file. unzip utility is not working for me in unix. Please help me resolve this issue Thanks ganesh. (3 Replies)
Discussion started by: Ganesh L
3 Replies

2. Shell Programming and Scripting

Using Shell Script in place of Perl script to Unzip the zip files.

Hi Expert, We have some shell scripts which Internally uses Perl Script to Unzip the source zip files which comes to inbound directory. So now our requirement is to avoid the dependency on Perl Script and us Shell Script to unzip the files. I have the Perl script with me attached can some one... (3 Replies)
Discussion started by: naveen.dasu
3 Replies

3. Shell Programming and Scripting

help with recursive handbrake script

I have a batch of mkv video files I would like to transcode to a more compressed format. After spending a significant amount of time experimenting with various parameters I think I have found the handbrake settings that give the best compromise. I now want to construct a simple bash script... (4 Replies)
Discussion started by: jonesal2
4 Replies

4. Shell Programming and Scripting

Unzip in bash script

My script works like this. 1. First for loop - checks if it can access zip parameters in a directory 2. If unzip fails for any of the file in that directory, then it goes inside the second for loop - to list which file is that 3. My doubt is..Is there any way I can tell status for every 5000... (17 Replies)
Discussion started by: vidhyamirra
17 Replies

5. Shell Programming and Scripting

help needed with creating challenging bash script with creating directories

Hi, Can someone help me with creating a bash shell script. I need to create a script that gets a positive number n as an argument. The script must create n directories in the current directory with names like map_1, map_2 etcetera. Each directory must be contained within its predecessor. So... (7 Replies)
Discussion started by: I-1
7 Replies

6. Shell Programming and Scripting

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

7. Shell Programming and Scripting

Shell script for unzip

All, I'm having 4 .zip files that are coming from FTP. I need to unzip those files and put that files into another folder. Can anyone help me how to write a shell script to check wether .zip files are located in FTP folder, if condition true then how to unzip and put it in another folder. Thanks in... (2 Replies)
Discussion started by: nvkuriseti
2 Replies

8. Shell Programming and Scripting

Recursive pid script

I'm trying to create a script that allows me to determine all the pid's that spawned from an original process(ie - who's running this command).... I've created a script that searches the processes running based on an argument passed the script. It then is to get the parent pid and look that... (3 Replies)
Discussion started by: jbarnhar
3 Replies

9. HP-UX

How to Unzip a .ZIP file in Unix without using unzip cmd..?????

Hi All I have ftped a .ZIP file (zipped using WinZip in Windows) to my Unix server (HP-UX). I don't have unzip cmd available in my curent Unix version Please let me know any cmd in UNIX (other than unzip) using which I can unzip this .ZIP file . Please elaborate on the commands aval and... (5 Replies)
Discussion started by: sureshg_sampat
5 Replies

10. Shell Programming and Scripting

unzip in script using rsh

Hi I have searched usr/bin and usr/sbin to try to find unzip but I cannot find it. My script is using the ksh #!/usr/bin/ksh but when I rsh to another box it cannot find unzip to unzip to a new archive, but I can unzip files when I am using a telnet session on the box. The error message... (4 Replies)
Discussion started by: speedieB
4 Replies
Login or Register to Ask a Question