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:
- Cut by Byte:-B (Byte)
- Cut by character:-C (character)
- 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