shell--pipe Command (pipe)

Source: Internet
Author: User

The pipe command is using the "| "This defining symbol

pipe Command "| "can only deal with the correct information coming through the previous command, i.e. Standard Output the information, for Standard Error and there's no direct processing capability.

The first data that is followed by each pipe must be "command", and the command has to be able to accept the data of Standrad input before it can be a "pipe command". For example , less,more,head,tail can accept pipe commands for standard input . As for ls,cp,mv , it's not a pipe order.

In other words, there are two main piping commands to note:

The pipe command only handles standard outputand is ignored for standard error output

the pipeline command must be able to accept data from the previous command as standard input to continue processing.

pick Command:cut,grep

Choosing a command is to analyze a piece of data, take out what we want, or get the line we want by analyzing the keyword. It is important to note that, in general, the selection of information is usually for "line" to analyze, not the whole piece of information analysis

Cut

Cut-d ' s-f fields for splitting characters

Cut-c character range for neatly arranged information

Parameters:

-D: followed by a split character, used with- f

-F: cut a piece of information into several segments based on the D-word split character, and use - f to remove the meaning of paragraph

-C:Remove the fixed-character interval in units of characters (characters),

For example

[Email protected]:/mnt/c/users/vivi# Echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

[Email protected]:/mnt/c/users/vivi# echo $PATH |cut-d ': '-F 5

/sbin

[Email protected]:/mnt/c/users/vivi# echo $PATH |cut-d ': '-f 3,5

/usr/sbin:/sbin

[Email protected]:/mnt/c/users/vivi# Export

Declare-x home= "/root"

Declare-x hosttype= "x86_64"

Declare-x lang= "en_US. UTF-8 "

Declare-x lessclose= "/usr/bin/lesspipe%s%s"

Declare-x lessopen= "| /usr/bin/lesspipe%s "

Declare-x logname= "Root"

[Email protected]:/mnt/c/users/vivi# export|cut-c 12-

Home= "/root"

Hosttype= "x86_64"

Lang= "en_US. UTF-8 "

Lessclose= "/usr/bin/lesspipe%s%s"

Lessopen= "| /usr/bin/lesspipe%s "

Logname= "Root"

Grep

Cut is a line of information to take out a part of what we want, and grep is to analyze a line of information, if there is the information we need, the line is taken out, the syntax is this

grep [-ACINV] [--color-auto] ' Find string ' filename

-A : find Data in a binary file as a text file

-C: calculate the number of times to find ' Find string '

- I: ignores case differences, so case is considered the same

-N: output line number by the way

-V: Reverse selection, which shows the line without the ' Find string ' content

--color=auto: You can add a color display to the Found keyword section

[Email protected]:/mnt/c/users/vivi# last| grep ' Root '

[Email protected]:/mnt/c/users/vivi# last| Grep-v ' Root '

[Email protected]:/mnt/c/users/vivi# grep--color=auto ' Stop ' catfile

OK now stop

shell--pipe Command (pipe)

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.