How to Use Unix Cut Command

In this tutorial, we will teach you on how to use the UNIX cut command.
Cut command is basically used to select or extract a chunk of text from a particular file. You can do that by specifying a particular range where the text is present in the file. You can even specify specific characters.

Step 1 – Use the cat command
Follow this step by step guide to learn how to use the Unix cut command.
For example in this tutorial, we have used the cat command first to display the output of the text file on the screen.
the cat command

Step 2 – Use the cut command
Next, we will use the cut command along with the different attributes. For example, if we type -c1 -c5 along with the cut command, it will only display the first through the fifth character of each line in the text file. In this manner, you can use use the cut command with attributes in Linux.
Cut command with attributes

Step 3 – Use the b switch
Similarly, we can use the b switch to fetch a range or single bytes of data from the text file. For example, we might want to display the first and the third character in the text file.
For that, we will type -b1,-3 followed by the name of the text file.
In this manner, only the first and the third character of each line is displayed on the screen over here.
B switch

Step 4 – Use the d switch
We can use the d switch along with the cut command to output data on the screen. We can even specify the range of fields that we want to be included in the output. For the purpose of this tutorial, we would be displaying the first field of each line in the text.
Similarly, we can change the value of the field switch to display the second field of the text file as well by changing the f1 to f2. In this manner, you can use the cut command in Linux.
Work with the d switch