Cut command in Unix full touch

Source: Internet
Author: User
Tags touch

The cut command reads content from a file or standard input and intercepts specific portions of each row and sends it to standard output.

There are three kinds of interception, one is by character position, the other is by byte position, three is using a delimiter to split a line into multiple fields, and to extract the specified fields.

The Cut command has 5 parameters, where-c,-b,-f represents "character", "Byte" and "Field" interception respectively. When intercepting in field mode, you need to specify a delimiter with the "-d" argument, which can only be a single character. There is also an "-S", suppress, which indicates that the row is not output if the delimiter is not given in the row (the default is to output the row without a separator)

Here are a few examples: intercept by character: Echo Hello, World | Cut-c 8-12 outputs "world" (12 characters from 8th to 12th in the Intercept string) by separator: echo Hello, World | Cut-f 2-d "" Then Output "world" (Interception of the second part separated by space) echo long, long ago | Cut-f 2,3-d "" is Output "Long, Ago" (Intercepting the 2nd and 3 parts separated by a space, note that the output is also separated by the delimiter specified by-D) using "-S" to silently ignore the line that did not give the delimiter: Echo Hello |cut-d "!"-F 1-s Nothing is output (because there is no "!" in the line) Characters

Returns 0 if the command executes successfully, and returns a number greater than 0 if an error is encountered.

One of the-c,-b, good understanding, the following I understand the-f parameter, oneself more test several times, multiple output several times, you understand.

# echo Long,long ago,ddddddd | Cut-f 2-d,
Long ago

# echo Long,long ago,ddddddd | Cut-f 2-D,
Long ago,ddddddd

# echo Long,long ago,ddddddd,hhhhhhhhhhh | Cut-f 2-D,
Long ago,ddddddd,hhhhhhhhhhh

The above three comparisons will be very clear.

# echo Long,long ago,ddddddd | Cut-f 2,3-d,
Long ago,ddddddd
# echo Long,long ago,ddddddd | Cut-f 1,3-d,
Long,ddddddd
# echo Long,long ago,ddddddd | Cut-f 1,2-d,
Long,long ago

# echo long,long ago Ddddddd | Cut-f 2-d,
Long ago DDDDDDD

# echo long,long ago Ddddddd | Cut-f 2,3-d,
Long ago DDDDDDD

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.