Linux Shell script programming-cut command

Source: Internet
Author: User
Cut

The cut command can extract text columns from a text file or text stream.

Cut syntax

[Root @ WWW ~] # Cut-D 'delimiter '-F fields <= used to have specific delimiter [root @ WWW ~] # Cut-C character range <= It is used for neatly arranged information options and parameters:-D: followed by separated characters. Used with-F;-F: Splits a piece of information into segments based on the-D separator, and uses-F to get the meaning of the segments;-C: take out a fixed character range in units of characters (characters;

 

The PATH variable is as follows:

[root@www ~]# echo $PATH/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/games# 1 | 2       | 3   | 4       | 5            | 6            | 7

 

Remove the PATH variable. I want to find the fifth path.

#echo $PATH | cut -d ':' -f 5/usr/local/bin

 

Remove the PATH variable. I want to find the third and fifth paths.

#echo $PATH | cut -d ':' -f 3,5/sbin:/usr/local/bin

 

Remove the PATH variable. I want to find the third to last path.

echo $PATH | cut -d ':' -f 3-
/sbin:/usr/sbin:/usr/local/bin:/usr/X11R6/bin:/usr/games

 

Remove the PATH variable. I want to find the first to third paths.

#echo $PATH | cut -d ':' -f 1-3
/bin:/usr/bin:/sbin:
 

 

Remove the PATH variable. I want to find the first, third, and fifth paths.

echo $PATH | cut -d ':' -f 1-3,5
/bin:/usr/bin:/sbin:/usr/local/bin

 

Practical example: show only the/etc/passwd user and Shell

#cat /etc/passwd | cut -d ':' -f 1,7 root:/bin/bashdaemon:/bin/shbin:/bin/sh

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.