LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-27-2006, 09:43 AM   #1
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Rep: Reputation: 30
replacing a file in a zip from command line


I'm using zip and unzip to set parameters on the fly in some java war files.

I can use the following:

unzip -p archive.war WEB-INF/web.xml | sed -e 's/ConfigFileLocation/helloworld/g' | zip -r archive.war -

The unzip works 100%
The sed works 100%

but...
The zip adds the edit to the file as a file called '-'

Using anything but '-' as the final parameter to zip gives the following:

zip error: Nothing to do!

Any ideas?

Davee

P.S. A war file is a correctly formatted zip file, by the way. :-)

Last edited by davee; 02-27-2006 at 09:45 AM.
 
Old 02-27-2006, 01:11 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
I don't think you need the -r flag. It means recursive and you're not recursing a directory structure. The man page gives the example:
Code:
tar cf - . | zip backup -
So, you could try:
Code:
zip archive.war -
I haven't tried it yet though.
 
Old 02-28-2006, 02:54 AM   #3
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Original Poster
Rep: Reputation: 30
Hi Gilead,

Thanks for that - I thought the same; but -r means 'replace' (-R is resursive). Without the -r I get the same error:

zip error: Nothing to do! (archive.war)

The only time I don't seem to get this error is wth 'zip -r archive.war -', which, as I say creates a file in the image called '-'

Any other ideas? This is really bugging me now- I can't believe unzip can work on the fly but zip cannot...
 
Old 02-28-2006, 01:06 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,123

Rep: Reputation: 162Reputation: 162
I think we're using different zip programs then. From the man zip page on my system:
Code:
       -r     Travel the directory structure recursively; for example:

                     zip -r foo foo

              In this case, all the files and directories in foo are saved in a zip  archive  named  foo.zip,
              including  files  with  names  starting  with ".", since the recursion does not use the shell's
              file-name substitution mechanism.  If you wish to include only a specific subset of  the  files
              in  directory  foo and its subdirectories, use the -i option to specify the pattern of files to
              be included.  You should not use -r with the name ".*", since that  matches  ".."   which  will
              attempt to zip up the parent directory (probably not what was intended).

       -R     Travel the directory structure recursively starting at the current directory; for example:

                     zip -R foo '*.c'

              In  this  case,  all  the  files matching *.c in the tree starting at the current directory are
              stored into a zip archive named foo.zip.  Note for PKZIP users: the equivalent command is

                     pkzip -rP foo *.c
Actually, thinking about this some more, it's a more complicated problem that I originally thought. With the unzip -p archive.war WEB-INF/web.xml you're extracting to stdout so that sed -e 's/ConfigFileLocation/helloworld/g' can modify a stream. What you want to do next is replace the contents of the file WEB-INF/web.xml in the archive with that stream. But you have no file, you have a stream with no file name.

I haven't tried it again, but it may be that you have to create the file (and the path to it?) and then replace the file in the archive with that. Having the path preserved complicates it slightly more than a flat archive would - but you can't get away from that structure with the .war file.

Sorry I couldn't solve it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
nfs a file shares ok via file mngr but not command line. Suse 9.1 acummings Linux - Networking 2 10-09-2004 02:23 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM
command line file management class_struggle Linux - Newbie 2 07-29-2004 02:50 PM
how to edit a file when not in X (ie from the command line) ludwig W Linux - Newbie 12 04-22-2003 04:00 AM
perl: replacing a special line in a file markus1982 Programming 1 09-26-2002 02:05 PM


All times are GMT -5. The time now is 07:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration