Ugly one-liner for gzip'ed gzip files

Had to rig up this one-liner to un-screw a situation were logrotate was configured to rotate and compress all files in a directory, including ones that had already been rotated and compressed; this sort of configuration lead to gzip'ed gzip files like this:


The one-liner I put together to loop through and gunzip the many gzip'ed layers is:

for i in $(ls *.gz*); do loops=$(echo $i | awk 'END{print _}{_+=NF-3}' FS=".gz"); filename=$(echo $i | cut -d '-' -f 1,2); zcat $i > $filename; for a in $(seq $loops); do gunzip -c $filename > $filename-tmp; mv -f $filename-tmp $filename; done; rm -f $i; done

Very ugly but you do end up with all the files in your directory named and working the way they should.