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:
- Cut by byte:-B (byte)
- Cut by character:-c (character)
- 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: