cut - remove sections from each line of files
parameter:
- -b bytes can be used to view the contents of the file
- -b parameters in Chinese, prone to garbled. Because the Chinese character by character occupies two bytes.
-
1 [root@oldboy oldboy]# head -n 10 /etc/passwd >test.txt 2 [root@oldboy oldboy]# cat test.txt 3 root:x:0:0:root:/root:/bin/bash 4 bin:x:1:1:bin:/bin:/sbin/nologin 5 daemon:x:2:2:daemon:/sbin:/sbin/nologin 6 adm:x:3:4:adm:/var/adm:/sbin/nologin 7 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin 8 sync:x:5:0:sync:/sbin:/bin/sync 9 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown 10 halt:x:7:0:halt:/sbin:/sbin/halt 11 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin 12 uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
-
1 # columns for the first 1 2 [the root @ Oldboy Oldboy] # Cut 1 -b test.txt . 3 R & lt . 4 B . 5 D . 6 A . 7 L . 8 S . 9 S 10 H . 11 m 12 is U 13 is 14 # take 1-3 column 15 [Oldboy Oldboy the root @] # Cut 1-3 -b test.txt 16 Roo . 17 bin 18 is DAE . 19 ADM 20 is LP: 21 is SYN 22 is Shu 23 is HAL 24 Mai 25 UUC 26 is [the root @ Oldboy Oldboy] # Cut -b -3 test.txt 27 Roo 28 bin 29 DAE 30 ADM 31 is LP: 32 SYN 33 is Shu 34 is HAL 35 Mai 36 UUC 37 [ 38 is # take 1,3,5 , 9, scramble, but the overall result was output, from small to large display 39 [the root @ Oldboy Oldboy] # Cut -b 9,5,3,1 test.txt 40 RO :: 41 is bnx1 42 is Deo: 43 is AMX4 44 L :: : 45 Sn :: 46 is Sud: 47 HL :: 48 mi The :: 49 UC: 0 50 51 is # display 20 from the last one 52 is [the root @ Oldboy Oldboy] # Cut -b 20-1200 test.txt 53 is OT: / bin / the bash 54 is / sbin / nologin 55 : / sbin: / sbin / nologin 56 is ADM: / sbin / nologin 57 is OOL / LPD: / sbin / nologin 58 in : / bin / Sync 59 Down: / sbin: / sbin / the shutdown 60 in : / sbin / the HALT 61 ar/spool/mail:/sbin/nologin 62 var/spool/uucp:/sbin/nologin
- -c extracted by character, used for Chinese. In English with not much difference with the -b
- -d separator disposed
- -f according field selection, set the number of columns need to look
- -d and -f parameters to be used in combination
- The default is a tab cut as the separator
-
1 # the ":" as the delimiter, select the first six fields 2 [the root @ Oldboy Oldboy] # Cut -d: -f test.txt. 6 . 3 / the root . 4 / bin . 5 / sbin . 6 / var / ADM . 7 / var / spool / LPD . 8 / sbin . 9 / sbin 10 / sbin . 11 / var / spool / mail 12 is / var / spool / UUCP