cut remove sections from each line of files
man cut 参数说明
cut -bcdf file
-b 字节
-c 字符
-d 分割符默认是空格
-f 取对应的值
字节字母是一个字节,汉字是3个字节
截取字节值 date | cut -b 1
1 代表截取一个
1- 截取1位置后面的
1-2 代表截取到2位置结束
-2 代表截取到2位置结束 和1-2 一样的效果
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date
Wed Jun 29 16:12:59 CST 2016
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -b 1
W
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -b 1-
Wed Jun 29 16:13:09 CST 2016
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -b -1
W
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -b -2
We
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -b 2-3
ed
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -b -3
Wed
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -b 3-
d Jun 29 16:13:37 CST 2016
截取字符 cut -c 1 和字节的规则一样
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -c 1
W
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -c 2
e
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -c -2
We
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -c 3-4
d
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -c 3-5
d J
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -c 3-9
d Jun 2
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# date | cut -c 3-
d Jun 29 16:19:30 CST 2016
截取通过分割符号截取 cut -d : -f 1 规则和上面的一样
如果不写-d 默认分割就是空格 现在是分号
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# head -n5 /etc/passwd
root:x:0:0:root:/root:/bin/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
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# head -n5 /etc/passwd |cut -d : -f 1
root
bin
daemon
adm
lp
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# head -n5 /etc/passwd |cut -d : -f 1-2
root:x
bin:x
daemon:x
adm:x
lp:x
root@nginx02 /application/ngx_openresty/nginx/conf/extra
# head -n5 /etc/passwd |cut -d : -f 3
0
1
2
3
4