Executing Word Counts with Bash

 1 year ago
source link: https://fuzzyblog.io/blog/bash/2017/04/12/executing-word-counts-with-bash.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Executing Word Counts with Bash

Apr 12, 2017

I'm in the process of starting a new writing project and I wanted to make the process of getting metrics easier so I rolled together this bash script:

echo "Word Count:"
cat *.md | wc -w
echo "Page Count:"
cat *.md | wc -w | xargs -I{} expr {} / 250

If you're looking to do this yourself then these commands all go into a single text file and a chmod +x command on the file makes it executable.

Here's the output of this script:

Word Count:
Page Count:

The interesting tool here is expr which is a command line math tool. The 250 is a metric that I use for the number of words per printed page. I know in the modern era that a printed page is perhaps a bit of an anachronism but I find it very comforting to know that I wrote 15 pages today (which is what I actually turned out today).

What this does is:

  • take a collection of markdown files
  • count all the words in the collection of markdown files
  • count all the words in the markdown files and then feed that value into xargs which then feeds the value into expr and divides it by 250

Cross References:

Here are the places where I sourced some of these techniques:

Posted In: #bash #linux #shell

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK