cut lines of text display specific content parameters

Features:

cut each act is a processing target, cut command to specify the portion of the line display, delete files middle finger
given field. cut is often used to display file contents

format:

cut (option) (parameters) 

Options:

-b bytes (bytes) 

[root @ localhost ~] # who // output display as 
the root PTS / 2020-01-06. 1 18:52 (221.221.159.88) 
[the root @ localhost ~] # WHO | -b. 3 // Cut third byte 
O 
[root @ localhost ~] # the WHO | Cut -b 5 // output should be spaces

[root @ localhost ~] # who | cut -b 1-3,10 // Take 1 to 3 and tenth bytes! Note that not interchangeable positions 1-3 and 10 according to a certain order of byte
roop   

[root @ localhost ~] # who | cut -b -3 // first three bytes
Roo
[the root @ localhost ~] # WHO | all subsequent cut -b 3- // three bytes
ot pts / 1 2020 -01-06 18:52 (221.221.159.88)

 

  

-c character (characters) 

// - c and -d -c reflected in the difference in characters output 
if it is Chinese, then
-c will output a whole Chinese
Chinese -b only in bytes (8 bits) to calculate the output is garbled
to solve -b garbled: -bn -n can be used to tell not to cut open the multi-byte character

  

-f fields (fields) -d separator disposed

// specifically, is set "Spacer" re-set "Extraction of several fields," 
[the root @ localhost ~] # CAT / etc / the passwd | head -5 
the root: X: 0: 0: the root: / the root: / bin / the bash 
bin: X:. 1:. 1: bin: / bin: / sbin / nologin 
daemon: X: 2: 2: daemon: / sbin: / sbin / nologin 
ADM: X:. 3:. 4: ADM: / var / ADM: / sbin / nologin 
LP: X:. 4:. 7: LP: / var / spool / LPD: / sbin / nologin 

[the root @ localhost ~] # CAT / etc / the passwd | head -5 | Cut -d: -f . 1 
the root 
bin 
daemon 
ADM 
LP 
[the root @ localhost ~] # CAT / etc / the passwd | head -5 | Cut -d: -f 2 
X 
X 
X 
X 
X

  

Additional: a small cut of about bug

[the root @ localhost ~] # PS 
the PID the CMD the TTY the TIME 
4323 PTS / the bash. 1 00:00:00 
4716 PTS / PS. 1 00:00:00 
[the root @ localhost ~] # PS | -b3 Cut 
P 
. 3 
. 7 
. 7 

reasons: ps | cut itself will create a process, so when ps this process will be extracted, and then output to cut through the pipe, so the cut after the interception, the more out of the line, the reason will be repeated on a single line, because we happen to and the line to take the contents of the same characters only. 

[root @ localhost ~] # PS | Cut -b 5 
D 
3 
5 
6 

tried it or have not the same ha ha ha ha

  

Guess you like

Origin www.cnblogs.com/gaiting/p/12154817.html