cut命令

例1

$ cat test1
abcdefg
hijklmn
opq
rst
uvw
xyz
$ cut test1 -c 1
a
h
o
r
u
x
$ cut test1 -c 2,4-6
bdef
iklm
p
s
v
y
$ cut test1 -c -4
abcd
hijk
opq
rst
uvw
xyz
$ cut test1 -c 3-
cdefg
jklmn
q
t
w
z
$ cut test1 -c -3,3-
abcdefg
hijklmn
opq
rst
uvw
xyz

例2

$ cat test2
星期一
星期二
星期三
$ cut test2 -c 3
一
二
三
$ cut test2 -b 3
�
�
�

汉字是utf8编码,3字节

$ cut test2 -nb 9
一
二
三

例3

$ cat /etc/passwd | tail -n 5
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
icecream:x:992:987:Icecream Daemon:/var/cache/icecream:/bin/false
mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
news:x:9:13:news user:/:/sbin/nologin
$ cat /etc/passwd | tail -n 5 | cut -d : -f 1
postfix
apache
icecream
mysql
news
$ cat /etc/passwd | tail -n 5 | cut -d ' ' -f 1
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
icecream:x:992:987:Icecream
mysql:x:27:27:MySQL
news:x:9:13:news

省略-d表示以 分隔

原文地址:https://www.cnblogs.com/chenkkkabc/p/3300992.html