O'Reilly logo

Linux Shell Scripting Cookbook by Sarath Lakshman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Column-wise cutting of a file with cut

We may need to cut text by column rather than row. Let's assume that we have a text file containing student reports with columns, such as No, Name, Mark, and Percentage. We need to extract only the name of students to another file or any n-th column in the file or extract two or more columns. This recipe will illustrate how to perform this task.

Getting ready

cut is a small utility that often comes to our help for cutting in column fashion. It can also specify the delimiter that separates each column. In cut terminology, each column is known as a field.

How to do it...

In order to extract the first field or column, use the following syntax:

cut -f FIELD_LIST filename

FIELD_LIST is a list of columns that are ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required