Suppose I need to download a zipped archive containing thousands of compressed CSV files, and unzip it, and I want to use make for that process. The first step is easy:
myarchive.zip:
curl -o myarchive.zip 'http://path/to/archive.zip'
But before downloading the archive, I don't know the name of every file in it. This doesn't work.
extracted/*.csv: myarchive.zip
unzip myarchive.zip -d extracted
How do I let make know that all of these CSV files are targets?
It's not clear exactly what you want, but this is probably close:
ARCHIVE_DIR := extracted
.PHONY: archive
archive: myarchive.zip
unzip $< -d $(ARCHIVE_DIR)
myarchive.zip:
curl -o $# 'http://path/to/archive.zip'
Related
I have a series of zip archives from which I wish to extract one text file to an output directory. the file is in the general location:
archive.zip/archive/summary.txt
I have the following code that I thought should work:
for file in *.zip
do
name=${file##*/}
base=${name%.zip}
unzip -j $name/$base/summary.txt -d /$output/$file-summary.txt
done
However unzip cannot find the text files.
In the end the following did what I wanted:
for file in *.zip
do
name=${file##*/}
base=${name%.zip}
unzip -j "$name" "$base/summary.txt" -d "$output/$base"
done
I have a Makefile that builds a shapefile as an intermediate steps.
.INTERMEDIATE : senate_boundaries.shp
senate_boundaries.shp : Senate\ shape\ files.zip
unzip -j "$<"
A full shapefile comes with more than just a .shp, but also a .prj file, a .dbf file, and a bunch of others. These files are created when "Senate shape files.zip" is unzipped.
These other files are never an explicit target or dependency.
.INTERMEDIATE : senate_boundaries.prj senate_boundaries.dbf
does not seem to do anything.
How can I tell Make to clean up these other files?
You can add something like this to your recipe:
rm -f $(wildcard Senate\shape\*.prj)
But that will only work for that one file and you would have to manually add each extension to get rid of.
so something like this might do the trick:
rm -f $(shell ls Senate\shape\ | grep -v .shp&)
Another option is to unzip into a temp directory and then copy the file you want out and remove the the temp directory.
I have a tar archive which contains several text files. I would like to write a script to display (stdout) the content of a file without extracting it to the current directory.
Actually I would like to do the same as:
tar tf myArchive.tar folder/someFile.txt
cat folder/someFile.txt
rm -R folder
but without the rm...
I tried this way but it didn't work:
tar tf myArchive.tar folder/someFile.txt | cat
Thanks
Use x to extract, with f from archive file. Then add also option -O to direct extracted files to standard output.
tar xf myArchive.tar folder/someFile.txt -O
I have two zip archives. Say, set1 has 10 csv files created using Mac OS X 10.5.8 compress option, and set2 has 4 csv files similarly created. I want to take the 4 files from zipped archive set2 and add them to list of files in archive set1. Is there a way I can do that?
I tried the following in Terminal:
zip set1.zip set2.zip
This adds the whole archive set2.zip to set1.zip, i.e., in set1.zip now I have:
file1.csv, file2.csv,..., file10.csv, set2.zip
What I instead want is:
file1.csv, file2.csv,..., file10.csv, file11.csv, ..., file14.csv
where, set2.zip is the archive containing file11.csv, ..., file14.csv.
Thanks.
I don't know of a built-in OS X tool, but there's a zipmerge utility as part of the libzip package (hg repository available).
unzip set2.zip -d .tmpdir; cd .tmpdir; zip ../set1.zip *; cd ..; rm -r .tmpdir;
This script here should do it.
zipjoin.sh
#!/bin/bash
#Example: ./zipjoin.sh merge_into.zip merge_from.zip
mkdir .tmp
unzip $2 -d .tmp
zip $1 .tmp/*
rm -r .tmp
Hope that helps!
I have a folder full of zipped files (about 200). I would like to transform this into a folder consisting only of unzipped files. What would be the easiest and quickest way to do this?
Please note that I would like to remove the zipped file from the folder once it us unzipped.
Also, I'm on a Mac.
Thanks!
You can do something like:
for file in `ls *.zip`; do unzip -f $file; rm $file; done
We are looping through all the zip files in the directory, unzipping it and then deleting it.
Note that the -f option of zip will overwrite any file without prompting if it finds a duplicate.
You need to run the above one-line command on the command line from the directory that has the all the zip files. That one line is equivalent to:
for file in `ls *.zip` # ls *.zip gets the list of all zip file..iterate through that list one by one.
do # for each file in the list do the following:
unzip -f $file # unzip the file.
rm $file # delete it.
done
I found this answer which is a simple one liner to gunzip all .gz compressed files within a folder.
Basically you cd to the folder and then run
gunzip *.gz
If you want to only unzip files with a certain prefix you put that before the *
gunzip example*.gz
Easy as cake!