batch shell script to zip individual files in directory - help | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

batch shell script to zip individual files in directory - help

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-28-2008
wingchun22 wingchun22 is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 3 December 2008, 11:23 AM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
batch shell script to zip individual files in directory - help

help trying to figure out a batch shell script to zip each file in a directory into its own zip file

using this code but it does not work

Quote:
#!/bin/bash
echo "3gptozip converter"
for f in "$@"
do
zip -j "$f.zip" "$f"
done
echo "Finished with 3gptozip converter"
tryed this also

Quote:

#!/bin/bash
echo "3gptozip converter"
if (($# ==0))
then
echo "Usage: 3gptozip [3gp files] ..."
exit
fi
while (($# !=0 ))
do
zip $1.zip $1
shift
done
echo "Finished with 3gptozip converter"
nothing seems to work , just ends without zipping any files

i have over 3000 files i need to zip up individualy

files to be zipped are in this format 123.flv.3gp

hopfully ending up like 123.flv.3gp.zip

is the file structure the problem

running a single zip command from shell seems to work ok

thanks for help in advance
Sponsored Links
    #2  
Old 08-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts
The first script looks excellent, if you run it like 3gptozip *.3gp
Sponsored Links
    #3  
Old 08-28-2008
wingchun22 wingchun22 is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 3 December 2008, 11:23 AM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by era View Post
The first script looks excellent, if you run it like 3gptozip *.3gp

sorry to be a bit stupid but how or what do i change and where to make this work
am i not doing the

zip -j "$f.zip" "$f"


part right


or is there a problem, in the echo commands

i was tying to run it with

nohup ./3gptozip.sh &

and

./3gptozip.sh

but is that the problem

thanks, i'm new to shell scripting by the way
    #4  
Old 08-28-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 
Join Date: Mar 2008
Last Activity: 28 March 2011, 6:41 AM EDT
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 10 Times in 8 Posts
The problem is that you need to list the files you want to zip on the command line, the script doesn't contain this information. "$@" contains the arguments passed to the script on the command line.
Sponsored Links
    #5  
Old 08-28-2008
wingchun22 wingchun22 is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 3 December 2008, 11:23 AM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
how whould i do that in shell ??

is it something like

nohup ./3gptozip.sh *.3gp &

or

./3gptozip.sh *.3gp

or is that the incorrect way to do it, thanks for help by the way
Sponsored Links
    #6  
Old 08-28-2008
wingchun22 wingchun22 is offline
Registered User
 
Join Date: Aug 2008
Last Activity: 3 December 2008, 11:23 AM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
thanks works ok now
Sponsored Links
    #7  
Old 03-08-2009
jennyenve jennyenve is offline
Registered User
 
Join Date: Mar 2009
Last Activity: 10 March 2009, 5:39 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
zip individual files

how to zip individual files (.txt) into its own zip file.
is it something like

directory name 'test'

for file in test/* do zip $file.zip $file.txt?
it's not working. please help.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Executing a batch of files within a shell script with option to refire the individual files in batch goddevil Shell Programming and Scripting 2 01-09-2012 02:51 PM
HOW: Shell script accessing files located in individual logged in user. shekharjchandra Shell Programming and Scripting 1 05-02-2011 10:49 AM
Apply 'awk' to all files in a directory or individual files from a command line ScKaSx Shell Programming and Scripting 4 11-04-2010 06:50 PM
Help with shell script to batch process files in a directory Cannoli Shell Programming and Scripting 3 11-01-2009 12:57 PM
Converting Shell script to Dos batch files darwinkna Shell Programming and Scripting 1 05-12-2006 11:01 AM



All times are GMT -4. The time now is 01:54 AM.