- [Instructor] Hi and welcome to the second
section of this course, have a good command.
Unix like systems have the privilege of having
the best command line tools, they help us achieve
many tasks, making our work easier.
While each command has a specific focus,
with practice you'll be able to solve complex problems
by combining two or more commands.
Some frequently used commands are grep, awk, sed and find.
Mastering the Unix slash Linux command line is an art.
You'll get better at using it as you practice
and gain experience.
This section will introduce you to some of
the most interesting and useful commands.
Now we'll see the first video of section two,
concatenating with cat.
In this video we'll see basic and advanced uses of cat.
Cat is one of the fist commands that a command line
warrior must learn.
It is usually used to read, display or concatenate
the contents of a file, but cat is capable
of more than just that.
We even scratch our heads when we need to combine
standard input data as well as data from a file
using a single line command.
The regular way of combining the stdin data
as well as file data is to redirect stdin
to a file and then append two files.
But we can use the cat command to do it easily
in a single invocation.
The cat command is a very simple and frequently used
command and it stands for concatenate.
The general syntax of cat for reading contents is.
This command concatenates data from the files
specified as command line arguments.
To print content of a single file.
To print contents of more than one file.
Let's see how it works.
Cat can be used in a variety of ways.
Let's walk through some of them now.
The cat command can not only read from files
and concatenate the data, but can also read the input
from the standard input.
To read from the standard input use
a pipe operator as follows.
Similarly we can concatenate content from input files
along with standard input using cat.
Combine stdin and data from another file as follows.
In this example hyphen acts as the file name
for the stdin text.
The cat command has a few other options for viewing files,
let's go through them.
Getting rid of extra blank lines.
Sometimes text files may contain two or more
blank lines together, if you need to remove
the extra blank lines use the following syntax.
For example.
Alternatively we can remove all blank lines
using TR as discussed in the translating
with TR in this section.
Displaying tabs as carrot I.
It's hard to distinguish tabs in repeated space characters.
While writing programs in languages such as Python,
tabs and spaces have different meanings
for indentation purposes.
Therefore the use of tab instead of spaces
causes problems in indentation.
It may become difficult to track where the misplacement
of the tab or space occurred by looking
through a text editor, cat has a feature
that can highlight tabs.
This is very helpful in debugging indentation errors.
Use the minus capital T option with cat
to highlight tab characters as carrot I.
An example is as follows.
Line numbers.
By using the minus N flag for the cat command
will output each line with a line number prefixed.
It is to be noted that the cat command
never changes a file, instead it produces
an output on stdout with modifications to input
according to the options provided.
For example.
Minus N will make cat command output line numbers
even for blank lines.
If you want to skip numbering for blank lines
use the minus B option.
Great, we've successfully learned
about concatenating with cat.
In the next video we'll learn how to record
and play back of terminal sessions.