Filtering based on lines—head and tail
To display the content of a file, we will use the cat
command. The cat
command displays the whole file content on stdout
. However, sometimes, we are interested in viewing only a few lines of a file. In this case, using cat
will be tedious because we will have to scroll down to particular lines that we are interested in.
Shell provides us the
head
and tail
commands to print only the lines in which we are interested in. The main difference between both the commands is, head
prints the lines from the beginning of the files, and tail prints the lines from the end of the files.
Printing lines using head
The syntax is as follows:
head [OPTION] [FILE …]
By default, head
prints first 10 lines of each FILE to stdout ...
Get Linux Shell Scripting Essentials 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.