Linux cut command learning notes

Source: Internet
Author: User

Linux cut command learning notes

The cut command is also one of the most common commands in Linux.

As its name suggests, cut is used to cut data. Specifically, cut data is used in files. Cut is a processing object for each row. This mechanism is the same as sed.

There are three cut measurements for the cut command:

  1. Cut by byte:-B (byte)
  2. Cut by character:-c (character)
  3. Cut by domain:-f (field) specifies the delimiter when cutting by domain. The default Delimiter is a tab (\ t ).

 

In addition, the cut command also supports the range represented by numbers,

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 (bounded DED) byte, character or field

-M from first to m' th (bounded DED) byte, character or field

For example:

Cut by byte
Date | cut-B 1-5
2014
Date | cut-B 1-6
2014
Date | cut-B 1-7
2014

From the example above, we can see that the Chinese character "year" occupies three bytes.

Cut by character

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

Multiple positioning locations are separated by commas (,).

Cut by domain

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

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

10 useful Linux Command Interview Questions and answers

Linux Command cd

Cat for Linux commands

Linux Command alias/unalias

Linux Command Parsing: su root and su-root

Interactive input of Linux commands read

This article permanently updates the link address:

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.