Every Unix/Linux user (and maybe Windows users too) is familiar with the
wccommand that counts characters, words, and lines. It an easy way to see how large a text file is and is often useful in scripts when you want to capture how many words or lines a file contains. I’ve been using it for decades and never thought too much about it.
Now Stefan tweets something about
wcthat I didn’t know:
TIL: GNU’s wc (wordcount) counts newlines, not lines …
I immediately checked this on my Mac, which uses the BSD version of
wc, and got the same result. As Stefan says, it’s easy to get an off by one error. If you’re using
wcfor anything other than casual information—a script, say—you should take this quirk in
wc’s behavior into account.
Good safety tip. I think I learned about this already through experience but nice to have a reminder.