The biggest problem with counting lines is remembering the name of the utility, since its called “word count” and not “line count”. I tend to use this for doing things like piping grep to wc and counting the lines to give me an idea of how many occurrences of something there are. I also use it to count errors in weblogs or really anything else that I could do with summarising. The syntax is something like:
grep -R TODO * | wc -l
Using a count like this is especially good for things like auditing code, where I need to know how prevalent something is – or refactoring, where I’m looking for how many of a particular pattern are outstanding. Counting lines is also very compatible with my habit of making lists in text files.
This is the feature that the utility was originally designed for, and as you can imagine, its pretty good at that. As with most things, this blog post started life as a text file and when I got to this point I saved it and ran:
wc -w wc_article.txt
It outputs the number of words (272) and the name of the file, which is useful if you’re giving it a pattern to match.
Its a really convenient and versatile little program; I use it often and I hope others will find it useful too.