- [Instructor] Welcome to the next video of section three,
counting the number of lines,
words, and characters in a file.
In the previous video,
we have learned about fast command line navigation
using pushd and popd.
In this video, we'll see how to use wc
to count lines, words, and characters.
Wc is the utility used for counting.
It stands for word count.
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 video includes some tricky examples in other sections.
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
helps us perform that.
We can use various options for wc
to count the number of lines, words and characters.
Count the number of lines in the following manner.
To use standardized input,
use the following command.
Count the number of words as follows.
In order to count the number of characters,
use the following commands.
For example, we can count the characters
in a text as follows.
Minus n is used to avoid extra new line character.
To print the number of lines, words, and characters,
execute wc without any options.
Those are the number of lines, words, and characters
respectively.
Print the length of the longest line in a file
using the minus capital l option.
Awesome, we have successfully learned
how to count the number of lines,
words, and characters in a file.
In the next video,
we'll learn about printing the directory tree.