From Burly Plover, 5 Years ago, written in Bash.
  1. #!/bin/bash
  2. #Remove old list file
  3. rm font_family.txt
  4. #Print a list of all files in the directory, ignoring painful spaces
  5. find *.otf -print0 | while read -d $'\0' file; do
  6. #Checking only the first 5 letters of the name to see if they match
  7.         family=`echo "$file"|cut -c1-5`
  8. #Taking these first 5 letters, outputting them to a "family" list to check if they have enough to justify moving them
  9.         echo "$family" >> font_family.txt
  10. done
  11. #Sort out the list, strip to just a list of different families (i.e., one instance of each)
  12. for families in `cat font_family.txt | sort | uniq`; do
  13. #For each listing of a "family" in our unique list, check to see if there are more than 2 occurences of it in the text file (basically, counting if there are "3 or more" occurences of this particular family of font)
  14.         if [[ `grep -cw $families font_family.txt` -gt 2 ]] ; then
  15. #If so, inform us that we are moving them
  16.                 echo "Moving highers"
  17. #Make a directory for each different font family (which is our variable)
  18.                 mkdir "$families"
  19. #For each file by "family"[wildcards].extension we have, print the name (ignoring crappy spaces) to the "filenames" variable, then move said file to its relevant family folder
  20.                 find "$families"*.otf -print0 | while read -d '' -r filenames; do
  21.                         mv "$filenames" "$families"
  22.                 done
  23. #If we find a family which doesn't have enough count, simply echo the rather informative "family nope" statement
  24.         else echo "$families" "nope"
  25.         fi
  26. done