A little while ago I was wondering just how many words I’ve written on my blog. I was inspired by Wouter over at Brain Baking .
Now, I use a static site generator for my blog, the upshot of which is that the whole thing is just a big folder full of files. So counting up all the words is really easy with a simple shell command:
wc --total=only -w content/blog/*/*.md
55198
That’s 55,198 total words as of the time of this writing. Well that’s neat. With a little bit of awk
you can get the average too:
wc --total=never -w content/blog/*/*.md \
| awk '{total+=$1} END{print total, total/NR}'
55270 321.337
(The change in total word count is because I am running these commands as I write this post.)
And finally I have a breakdown of the number of posts by year.
rg "^date: \d{4}-\d{2}-\d{2}" -t markdown -o content/blog \
| cut -d' ' -f2 \
| date -f - +"%Y" \
| sort | uniq -c \
| awk 'BEGIN{print "|Year|Number of posts|\n|----|----|"; OFS="|"}
{printf "|%-4s|%-4s|\n", $2, $1}'
That one is a little more complicated… But in brief it searches my files for the date each post was published and tallies up the number of files in each year. With a bunch of wrangling to get everything in the right format. There is an impulse to downplay that part, but really a large amount of programming consists of wrangling data into the right format.
That gets us some information that is hopefully interesting to someone besides me.
I copied this set of stats from Joel
. The nice thing about them is that they are very easy to do. I have ideas for more complex data to show about my blog, but that is beyond my skills with shell scripting, so this will have to do for now. There are a number of bash wizards on my Mastodon timeline, but I am just not one of them. But the beauty of it is that you do not need to know all that much to do some cool things.