Q

Emertxe-News & Blog

Home » Blog » Cut command : Filtering what you want
Cut command : Filtering what you want
As a sequel to the previous article about Split command, thought of sharing another useful command called ‘cut’ that is available in Linux environment.

Similar to split, often we run into some situations where configuration to be read from a particular file which is delimited with some identifiers (ex: comma or colon symbol) where the cut command comes into picture. While the cut offers multiple options, for simple understanding purpose, the following syntax helps to split based on the colon as delimiter.

  1.                                 cut –d <delimiter> -f<field name>

Let us take for example cut_demo file (which is a local copy of /etc/password) file in linux which is de-limited by “:” as delimiters, which can be split as follows.

cut_screenshot_1

Fig1: Contents of /usr/password

Suppose we are only interested in the first field (that is name field) that can be obtained as follows:

  1.                                 cut –d”:” –f1 cut_demo

cut_screenshot_2

Fig2: Obtaining only username using cut command

The output of the command is nothing but the username, cut form the file /etc/password is displayed in the standard output. A sample output provided below. By re-directing it to a different file, further processing on username can be done by a user program. While the split command helps the user to partition contents at file level, the cut command helps and programmer to partition the contents from inside the file, using particular delimiters.

I hope you are able to appreciate practical usage of split and cut command in the past two blog posts. Let us explore more useful commands in future posts.

YOU MAY ALSO LIKE

Our Training Programs for Freshers

Our Training Programs for Freshers

Introduction: Emertxe is the leading training institute in Bangalore for Embedded Systems and IoT domains. It is a pioneer in training freshers since 2003 by providing excellent placement opportunities for freshers. Over the years 70000+ students have made their...

Difference between typedef and macro in C

Difference between typedef and macro in C

Introduction In any programming language, there are a set of keywords available, which can’t be used as variable name. It is because keywords are reserved and they have a special meaning. Keywords which are also called as reserved names can be anything like a command...

Emertxe and ESSCI launch Virtual Internships for Engineering students

Emertxe and ESSCI launch Virtual Internships for Engineering students

Emertxe, India’s premier embedded systems engineering finishing school, has provided more than 650+ students placements in 2019-20 alone. During 2020, amidst challenging pandemic times it continues to support students with placement opportunities and new programs via...

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *