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