O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

Counting the number of lines, words, and characters from a text or file are very useful for text manipulations. In several cases, count of words or characters are used in indirect ways to perform some hacks to produce required output patterns and results. This book includes some of such tricky examples in other chapters. Counting LOC (Lines of Code) is an 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.

Getting ready

wc is the utility used for counting. It stands for Word Count (wc). Let's see how to use wc to count lines, words, and characters.

How to do it...

Count ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required