2
I have a few thousand gzipped text files in different subdirectories and used a subset of these files as input for a project a few years ago. Back then I had an unzipped copy of the files I actually used in one directory, but deleted this and kept only a list of these unzipped files in that folder
This was my initial idea, LIST
is the list of files. PARENTDIR
is the toplevel directory in which all files reside in various sub directories. The idea was to find all the archives in whatever sub directory they are and gunzip them to NEWDIR
#!/usr/bin/env bash
LIST="listfile.txt"
PARENTDIR="/home/user/old/project"
NEWDIR="/home/user/old/project/2016"
while read line;
do
ARCHIVE="$(find $PARENTDIR -name "$line*")"
gunzip --stdout $ARCHIVE >$NEWDIR/$line
done <$LIST
I don't seem to get the find command right. It works without the variables, but not with, even without the command substitution, calling on the command line. My combination of quotes and wild cards is not quite correct, but I can't get it right, variable expansion doesn't help either and I guess I'm stuck...
Add
echo "$ARCHIVE"
to see what it happened... orset +
before andset -
after the part to debug. If there are spaces you want to use" $variable"
... what happens if find found more than one archive compliant with the key? Betterfind... -exec gzip {} ;
– Hastur – 2016-06-29T08:29:00.443Thank you for the suggestion,
echo "$ARCHIVE"
outputs an empty line,echo $line
shows what I expect. I includedset +
andset -
but nothing seemed to happen either - but I'm not exactly familiar with set – Carambakaracho – 2016-06-29T08:46:45.583@Hastur, you're right, my tests show I have a few thousand duplicates, but not all. In principle, the first text file could be overwriten by the second, would
find... -exec gzip {} ;
just decompress the archive twice as well? – Carambakaracho – 2016-06-29T08:54:25.870