Shell -- cut usage,

Source: Internet
Author: User

Shell -- cut usage,

Cut is a processing object for each row. This mechanism is the same as sed.

Cut accepts three positioning methods:

1) byte:-B

2) characters:-c

3) fields:-d

Eg: extract the 3, 4, 9 Bytes: cut-B 3-5, 9

Note: If you use the-B Option for the cut command, all the positions after-B are sorted from small to large before extraction. The order cannot be reversed.

-3 indicates from the first byte to the third byte;

3-indicates from the third byte to the end.

For Chinese extraction,-c is measured in characters and the output is normal.-B is calculated in bytes (8-bit binary.

If you encounter multi-byte characters, use the-n option to remove the multi-byte characters. Cut-nb 1, 2, 3

 

For non-fixed format information, the domain is required. You need to set the delimiter before extracting the nth domain.

Cut-d:-f 1

-D: Set the delimiter to-f 1 to extract the first domain.

Note: How can I identify spaces and tabs?

First, check whether the space consists of spaces or tabs:

Cat tab_space.txt

Sed-n l tab_space, txt

If it is a TAB, \ t is displayed. If it is a space, it is displayed as is. (L after n in sed is lower case L)

What symbols does cut-d use to represent tabs or spaces?

The default cut-d interval is tab, which can be omitted. If space is set as the delimiter, cut-d ''-f 4

(There must be a space in two single quotes)

In addition, only one space can be set after-d, and multiple spaces are not allowed. The delimiter allowed by cut is a character.

Reference: http://blog.sina.con/cn/s/blog_5e77c61f0100hqky.html

 

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.