I. Cut function-remove sections from each line of files (man cut)
Is responsible for cutting data in the file, andTake each row as a processing object, similar to SED, which is very useful in processing text data.
Ii. Command Format and locating methods
Cut option... [file]...
The cut command mainly accepts three positioning methods:
1, byte (bytes, in ascending order), with option-B
2, character (characters, if it is Chinese, it may be two bytes), use option-C
3, field (fields), with option-F
Iii. Examples
1. Extract 3rd bytes
Ll/dev/SDA *
BRW-RW ---- 1 root disk 8, 0 2012-03-20 13:13/dev/SDA
BRW-RW ---- 1 root disk 8, 1 2012-03-20 13:13/dev/sda1
BRW-RW ---- 1 root disk 8, 2 2012-03-20 13:13/dev/sda2
BRW-RW ---- 1 root disk 8, 3 2012-03-20 13:13/dev/sda3
Ll/dev/SDA * | cut-B 3
W
W
W
W
2. Extract multiple bytes
Ll/dev/SDA * | cut-B 1-8, 12
BRW-RW -- 1
BRW-RW -- 1
BRW-RW -- 1
BRW-RW -- 1
3. Other tips on Byte
1-
-3
-3, 3-
4. Extract characters
It is similar to byte-based, but if it is Chinese (multiple bytes), the extraction of byte may be garbled.
5. Extract the domain (this is the most useful)
It mainly specifies a delimiter (-d) and the domain (-F) to be extracted, as follows:
Ll/dev/SDA * | cut-d''-F1, 7-9
BRW-RW ----/dev/SDA
BRW-RW ----/dev/sda1
BRW-RW ----/dev/sda2
BRW-RW ----/dev/sda3
6. About
When the field is extracted, cut is distinguished by tabs (\ t) by default. to distinguish between tabs and spaces in text, run the following command:
Sed-N LFilename
Xin \ tjiang \ TLI \ tzong $
Xin \ tjiang \ TLI \ tzong $
$
Cut can only process text content separated by a single character. If multiple consecutive spaces (occupying multiple fields), it is more troublesome.