How to Display Data from a Text File in Linux


When using Linux, you frequently work with different text files, and using the Linux operating system Ubuntu 22.04, we will cover various methods for extracting data from text files.

The display of text file data on the Ubuntu terminal screen is covered in great detail in this article. To understand more, read the article.

Display Data from a Text File on Linux Terminal

Seven different approaches have been discussed below to display data of Text files on Linux terminal:

Use cat Command to Display Data from a Text File

Concatenate, sometimes known as “the cat,” is preloaded in newer versions of Ubuntu; if you are using an earlier version, you must install it. It is a frequently used command that reads every bit of information from a file and displays it on the terminal screen. We can create, examine, and merge files thanks to it.

Your terminal will get cluttered, and navigating will be challenging if you use the cat command to show the contents of large text file(s) to the terminal.

Syntax:

$ cat [options] filename

The command listed below will show the whole contents of the “linux.txt” file on the screen:

$ cat linux.txt

Display-Data-Text-File

Display-Data-Text-File

You can run the following command to get more details about the man command:

$ man cat

Display-Data-Text-File

Display-Data-Text-File

Use nl Command to Display Data from a Text File

This preinstalled command is similar to cat, except that it numbers lines from a file or STDIN, copies them to STDOUT, and displays them on the terminal by appending line numbers.

Syntax:

$ nl [options] filename

Using the nl command, the following command will show the whole contents of the “linux.txt” file on the screen:

$ nl linux.txt

Display-Data-Text-File

Display-Data-Text-File

Use less Command to Display Data from a Text File

A pre-installed tool called Less enables you to view a file’s contents one page at a time. By hitting the space key, you may navigate the text file. Two colons at the bottom of the terminal signify each page of the text file. By hitting “q,” you can leave.

Syntax:

$ less [options] filename

This command works well with larger files since it shows one page at a time, making it simple to examine larger files. The following command will show the whole contents of the “linux.txt” file on the screen with only one command:

$ less linux.txt

Display-Data-Text-File

Display-Data-Text-File

You can find more about this command by typing the below syntax:

$ man less

Display-Data-Text-File

Use more Command to Display Data from a Text File

A built-in command called more is like less in that it opens a text file so you may read it page by page and leaves no output on the screen when you depart.

Syntax:

$ more [options] filename 

Using the additional command shown below, the “linux.txt” file’s whole contents will be displayed on the screen:

$ more linux.txt

Display-Data-Text-File

You can find more details about this command by writing the below command:

$ man more

Display-Data-Text-File

Display-Data-Text-File

Use head Command to Display Data from a Text File

By default, the head command displays the “top 10 lines” of a specified text file which makes it slightly different than other commands. By using different options of the head command, you can change the way of displaying content.

You can see the content of any text file using the command mentioned below:

$ head linux.txt

Head-Command-Display-Data-Text-File

Display Data from a Text File Using tail Command

The opposite of the head command is a built-in command called the tail. The head command by default only shows the “latest 10 lines” of a given text file. You may alter how the material is shown by using different head command parameters by following the syntax below:

$ tail linux.txt

Display-Data-Text-File-Linux

Conclusion:

Text files include several types of text, and you may view their commands by using any of the methods mentioned in this article.

Read the whole article to learn more about each command in detail as we examine a range of techniques for extracting text from text files and displaying it on the terminal.

Print Friendly, PDF & Email
Categories