Linux Shell script Programming--cut command

Source: Internet
Author: User

Cut

The Cut command extracts text columns from a text file or text stream.

Cut grammar

[[email protected] ~]# cut-d ' The delimiter character '-f fields <== used to have a specific delimiter character [[email protected] ~]# cut-c character interval            <== used to arrange neat information options and parameters:- D  : followed by delimited characters. Use with-F;  -F: Divides a piece of information into several segments according to the delimiter character of-D, and uses-F to remove the meaning of the paragraph;-C  : Remove the fixed character interval in the unit of character (characters);

The PATH variable is as follows

[Email protected] ~]# echo $PATH/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/x11r6/bin:/usr/games# 1 | 2       | 3 |   4       | 5            | 6            | 7

To take the path variable out, I'm going to find a fifth path.

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

Take the path variable out and I'll find the third and fifth paths.

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

Take the path variable out and I'll find the third to last path.

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

Take the path variable out and I'll find the first to third path.

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

Take the path variable out, I want to find the first to third, there is a fifth path.

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

Practical Example: Display only/etc/passwd users and shells

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

Linux shell script programming--cut commands

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.