I have many folders and files of the following type:
├── name 1.htm
├── name 2.html
├── name 1_files
│ ├── some files
├── name 2_files
│ ├── some files
I need for each .htm or .html file to find the appropriate folder with the same name, but with a "_files" at the end.
Then I need to put the found file and folder in another folder, for example, '000' and zip it.
Then I need to move the resulting .zip file to another folder, for example, 'Found'.
I'm a newbie to bash and scripting in general so any help would be appreciated.
Here is a zip-by-prefix.sh script that you can run from the directory where the the htm* files are present :
mkdir -p found
ls *.htm* > htmlfiles.txt
cat htmlfiles.txt | cut -d"." -f1 | uniq > htmlprefixes.txt
PREFIXES=$(echo `cat htmlprefixes.txt`)
for prefix in $PREFIXES
do
mkdir -p 000$prefix
cp $prefix* 000$prefix
zip -r 000$prefix.zip 000$prefix
mv 000$prefix.zip found
done
rm *.txt
Explanation
Finally check if the "found" directory contains all the zip files