The cut of Linux command learning

Source: Internet
Author: User

The Cut command is also one of the most commonly used commands under Linux.

As its name, cut's job is to "cut", specifically in the document is responsible for cutting the data used. Cut is a processing object for each line , and this mechanism is the same as SED.


There are three cut metrics for cut commands:

    1. Cut by Byte:-B (Byte)
    2. Cut by character:-C (character)
    3. Cut by field:-F (field) you need to specify a separator when cutting by field, and the default delimiter is a tab character (\ t).


In addition, the Cut command supports the range of digital representations,

n n ' th byte, character or field, counted from 1

N-from N ' th byte, character or field, to end of line

N-m from N ' th to M ' th (included) byte, character or field

-M from first to M ' th (included) byte, character or field

Example to illustrate:

Cut by byte
Date | Cut-b 1-5
2014
Date | Cut-b 1-6
2014
Date | Cut-b 1-7
2014

From the above example, we can see that the Chinese character "year" accounted for 3 bytes


Cut by character

Date
Friday, October 10, 2014 14:48:16 CST
Date | Cut-c 1,3,4
214

Multiple positions separated by commas


Cut by Field

Date
Friday, October 10, 2014 14:46:09 CST
Date | Cut-d ""-F 4,5
Friday 14:46:12

-D indicates the separator and the delimiter must be a single character.


Reference: http://www.cnblogs.com/xianghang123/archive/2011/12/06/2277531.html

The cut of Linux command learning

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.