Digital Magpie

Ooh, ooh, look - shiny things!

Category Counts in Octopress

Here’s a quick shell script to get the number of posts in each category for an Octopress blog, just cat your source/_posts folder through the following one-liner:

sed -n '/^---/,/^---/p' |\
grep '^- ' |\
sort |\
uniq -s 2 -c - |\
sort -n

Here’s what each line does:

  1. extracts the Yaml front-matter from each file;
  2. extracts each top-level list entry, this assumes that the only top-level list is the category list, which is the default for Octopress posts;
  3. sort the lines;
  4. collapse identical lines, prepending a count of the number of lines collapsed; and finally
  5. sort numerically.

Maybe this will be useful to somebody out there…

Update: I’ve written a version that’s integrated with rake as well.