Chapter 2 understanding and learning bash pipeline commands (PIPE)

Source: Internet
Author: User

Pipeline commands use '|' to define symbols

[[email protected] ~]# ls -al /etc | less

The pipeline command "|" can only process the correct information sent through the previous command, that is, the standard output information. It does not directly process stdandard errors.


Figure 6.1.1 pipeline command processing
  • Pipeline commands only process standard output. Standard Error output is ignored.
  • Pipeline commands must be able to accept the output data from the previous command as standard input for further processing.

Capture command: Cut, grep

Retrieving information is usually analyzed for "one row and one row", not the whole information analysis.

  • Cut
[[Email protected] ~] # Cut-D 'delimiter '-F fields <= used to have specific delimiter [[email protected] ~] # 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 a fixed character interval in the unit of character (characters). Example 1: retrieve the PATH variable. I want to find the fifth path. [[Email protected] ~] # Echo $ path/bin:/usr/bin:/sbin:/usr/local/bin:/usr/x11r6/bin:/usr/games: #1 | 2 | 3 | 4 | 5 | 6 | 7 [[email protected] ~] # Echo $ PATH | cut-d': '-F 5 # As shown in the preceding figure, we separate them, so/usr/local/bin # will appear. What if you want to list 3rd and 5th ?, [Email protected] ~] # Echo $ PATH | cut-d': '-F 3, 5 Example 2: obtain the information output from the export, and obtain all strings after the 12th characters [[email protected] ~] # Exportdeclare-x histsize = "1000" declare-x inputrc = "/etc/inputrc" declare-x kdedir = "/usr" declare-x lang = "zh_tw.big5 "... .. (others omitted )..... # Note: Every data is neatly arranged! If we do not want "declare-X", # do this: [email protected] ~] # Export | cut-C 12-histsize = "1000" inputrc = "/etc/inputrc" kdedir = "/usr" lang = "zh_tw.big5 "..... (others omitted )..... # Do you know what's going on? -C can be used to process formatted data! # We can also specify a value range, for example, the characters 12th-20 are cut-C 12-20! Example 3: Use last to display the login information, leaving only the user name [Roo [email protected] ~] # Lastroot pts/1 192.168.201.101 sat Feb 7 still logged inroot pts/1 192.168.201.101 Fri Feb 6-() Root pts/1 127thu Feb 5) # Last can output "account/Terminal/source/Date and Time" data, which is neatly arranged [email protected] ~] # Last | cut-D ''-F 1 # From the output result, we can find that the first blank field separated represents the account, so use the following command: # But because there are several spaces between root pts/1, not only one space exists, if you want to find out # PTS/1, you cannot use cut-D ''-F! The output result is not what we want.

The main purpose of cut is to "break down the data in the same row !』 It is most often used when analyzing some data or text data! This is because sometimes we take some characters as split parameters and then cut the data to get the data we need.

 

Chapter 2 understanding and learning bash pipeline commands (PIPE)

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.