Remove all files except for last file of each month
With the file zz containing the list of file names, this works, so just replace cat zz.
cat zz | grep -vF -f <(cat zz|sort -r|uniq -w11)
e.g. echo *.sql | grep -vF -f <( echo *.sql | sort -r | uniq -w11 ) | xargs rm
As is, it won't work if spaces in file names, and very fragile to filename length.