Linux command (a) cut

Source: Internet
Author: User

1. Role

Cut is a selection command that analyzes a piece of data and takes out what we want. In general, the selection of information is usually for "line" to analyze, not the entire information analysis.

2. Usage

Cut "parameter" "File or stdin"

Parameters :

-D: followed by delimited characters, used with-F, the Default Field Delimiter is Tab tab;

-F: Cut a piece of information according to the delimited character of-D and remove the paragraph with-F;

-B: Split in bytes;

-C: split in characters;

-N: With-B, do not split multibyte characters;

--complement: extracts a column other than the specified field .

scope indicates :

N: From Nth Byte, character, field to end;

N-m: bytes, characters, fields from Nth Byte, character, field to M (including m);

-N: From the 1th Byte, character, field to Nth (including N) bytes, characters, fields.

3. Give examples

3.1 cut-d ': '-F 1

Note: Cut will first sort all the positions after-F and then extract them, so the results will not reverse the order.

Note: The result is that the entire row is output and no repetition of the 3rd field occurs.

Question: What symbols are used in cut-d to set tabs or spaces?

Multiple Spaces and Tabs tab how to see, with the sed-n L File command, L is the lowercase letter L:

Note: The space or the original Display, Tab tab display is \ t, line break is $

The default delimiter is tab-tab:

With a space as a delimiter, the-D quotation marks directly after a space can be:

More than one space in the quotation mark after-D will make an error:

Note: If some fields within a file are spaced by several spaces, then using cut is a bit of a hassle, because cut is only good at dealing with text content "at a single character interval."

3.2 Cut-b 2

Take out the 2nd byte of each line:

3.3 Cut-c 2

Remove the 2nd character of each line:

Note: The English letters are single-byte characters, so the results of-B and-C are the same, if Chinese is different:

3.4 cut-nb 1-3 File

Note: When multi-byte characters are encountered, you can use the-n option, which is used to tell the cut not to disassemble multibyte characters.

But not add-N also can, embarrassed ...

3.5 cut-d '-F 2--complement file

Extracts a column other than the specified field:

Linux command (a) cut

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.