How to zip files that are listed in text file?
I have a list of files to zip in a text file.(full path and file name)
I want to be able to zip those files up. Any help would be greatly appreciated. I tried googling and no luck. I tried zip myzipfile.zip < input.txt did not work. How do I do this? Thanks |
Code:
cat input.txt | zip myzipfile.zip -@ |
Thank you it works. I read the man page and learned about -@ reads from stdin.
Now I have one problem with this approach. So the path of my list of files in the text files appear like this(I am using cygwin btw) /cygdrive/c/foo/file1.txt /cygdrive/c/foo2/file2.txt .. etc I want it to be like foo/file1.txt foo2/file2.txt in the resulting zip file. How can I accomplish this. (changing the resulting zip files content path change) Hope it makes sense. |
The zip command hasn't got an option to automatically remove part of the path from the file name, so that you have to do some scripting. Here is an example:
Code:
#!/bin/bash |
Thanks for the reply. I am getting some syntax error.
$ ./zip_it_correct.sh ./zip_it_correct.sh: line 8: syntax error near unexpected token `done' ./zip_it_correct.sh: line 8: `done < input.txt' |
I cannot tell what the problem is without looking at your actual script. Moreover posting some lines of the real file input.txt would help.
|
input.txt context
/cygdrive/d/data/01-03-2011/file1.txt /cygdrive/d/data/01-04-2011/file2.txt /cygdrive/d/data/01-05-2011/file3.txt output.zip needs to include data/01-03-2011/file1.txt and not include /cygdrive/d the script is basically I am using what you gave me Code:
#!/bin/bash |
I cannot see any problem. Maybe running the script as
Code:
bash -x zip_it_correct.sh Anyway, here is an awk alternative that does exactly the same and uses the shell to execute the cd and the zip commands: Code:
awk '{ |
Ok thanks for the reply. That awk script works. I just needed to do little tweak.
awk '{ file=gensub(/(.*)/,"\\1",1) print "cd /cygdrive/c/","&& zip -g $HOME/output.zip", file | "/bin/sh" }' input.txt I just needed to eliminated the first two folders. I also modified my input.txt file a little so now it has foo/file1.txt foo/foo2/file2.txt ..... etc This forum is awesome. Quick replies. |
Well.. if the solution is simply to change to directory /cygdrive/c, that is all the files are under this node, why not simply do the following (after the applied change to input.txt)?
Code:
cd /cygdrive/c |
No the solution you provided earlier was correct. Since I am not running this script from /cygdrive/c/ location. I am running it from another drive and location. In the resulting zip file it cannot have /cygdrive/c/ in the front. So that awk script worked well.
|
All times are GMT -5. The time now is 07:29 AM. |