Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best way to extract a file from a zip file and put it back into the zip file after editing

Tags:

shell

I am wondering if anyone can help me with a shell script to do the following job:

Extract a file from a zip file and put it back in after some editing, e.g. using sed to do some replacement.

I want to avoid extracting all contents of the zip file into a temporary folder. It could be possible that the zip file contains files with the same name as the one I want to replace with editing. In such case, I want to specify the full path of such file inside the zip file.

Is there any good way to do this task?

like image 349
Qiang Li Avatar asked Apr 07 '11 22:04

Qiang Li


1 Answers

  1. Extract a file from a zip file:

    unzip file.zip file/you/want/to/extract/the_file.txt

  2. Modify the_file.txt

  3. Put it back:

    zip file.zip file/you/want/to/extract/the_file.txt

That should get you started.

like image 80
holygeek Avatar answered Oct 22 '22 07:10

holygeek