Counting the number of lines, words, and characters in a file

Counting the number of lines, words, and characters from a text file are very useful for text manipulations. In several cases, these counts are used in indirect ways to perform some hacks in order to produce the required output patterns and results. This book includes some tricky examples in other chapters. Counting LOC (Lines of Code) is a very important application for developers. We may need to count special types of files excluding unnecessary files. A combination of wc with other commands help to perform that.

wc is the utility used for counting. It stands for word count . Let us see how to use wc to count lines, words, and characters.

How to do it...

We can use various options for ...

Get Linux Shell Scripting Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.