#/!/bin/bash
# "les fichiers total et total-1 sont (re)créés dans un chacun des dossiers concernés, le tout mixé dans total_des_fichiers_total et total_des_fichiers-1"

# évite d'ajouter des anciens fichiers 'total' !
erg-vide_historiques

# sh total_des_totaux.sh
if [ -f total_des_fichiers_total ]
then
	rm total_des_fichiers_total
fi
pwd=$PWD
echo "PWD=$PWD"
ls | grep "^classes-" | while read i
do
	echo "cd $pwd/$i"
	cd "$pwd/$i"
	erg-fusion-total
done

find -name total | grep classes | sort | sed -e "s/\.\///g"   | while read i
do
        # ne pas oublier de reconstruire le fichier en cas d'erreur
        if [ -f "$i" ]
        then
                echo "cd $(echo "$i" | sed -e "s/\/total//g") ; erg-fusion ; cd .."
                cd $(echo "$i" | sed -e "s/\/total//g")
                # erg-fusion (inutile, fait plus haut)
                cd ..
		echo -e "\n$i" | sed -e "s/./-/g" >> total_des_fichiers_total
		echo -e "\n$i" >> total_des_fichiers_total
		echo "cat "$i" >> total_des_fichiers_total"
		cat "$i" >> total_des_fichiers_total
        fi
done
if [ -f total_des_fichiers_total-1 ]
then
        rm total_des_fichiers_total-1
fi

find -name total-1 | grep classes | sort | sed -e "s/\.\///g"  | while read i
do
        # LOG echo "total-1 : $i"
        echo -e "\n$i" | sed -e "s/./-/g" >> total_des_fichiers_total-1
        echo -e "\n$i" >> total_des_fichiers_total-1
        cat "$i" | grep -v "^ *1 " >> total_des_fichiers_total-1
done

# echo "les fichiers total et total-1 ont été (re)créés dans un chacun des dossiers concernés, le tout mixé dans total_des_fichiers_total et total_des_fichiers-1"
