Linux Shell script Programming--cut command __HTML5

Source: Internet
Author: User

Cut-and

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

Cut syntax

[root@www ~]# cut-d ' delimited character '-f fields <== used with specific separator characters
[root@www ~]# cut-c character interval            <== for neat information
options and Parameters:-
D  : followed by a separator character. Used in conjunction with-
F  : Splits a piece of information into several paragraphs with-D, using-F to remove the meaning of paragraph,-
C  : The fixed character interval is taken out of the unit of character (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

Take the path variable out and I'll find the 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'm going to find the third to the 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'm going to find the first to the third path.

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

Take the path variable out, I'm going to find the first to third, and the fifth path.

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/bash
daemon:/bin/sh
bin:/bin/sh

Source: http://www.cnblogs.com/zwgblog/p/6006102.html

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.