8种机械键盘轴体对比
本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?
cut - 输出文件行的选定部分到标准输出。
如果不指定 File 参数,cut 命令将读取标准输入。必须指定 -b、-c 或 -f 标志之一。
主要参数OptionContent-b以字节为单位进行分隔。这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志
-c以字符为单位进行分隔
-d自定义分隔符,默认为制表符
-f与 -d 一起使用,指定显示哪个区域
-n取消分隔多字节支付。仅和 -b 一起使用。如果字符的最后一个字节落在由 -b 标志的 list 参数指示的范围之内,该字符将被写出;否则,该字符将被排除
以字节定位
举例:当你执行 who 命令时,会输出如下内容:1
2
3root pts/0 2016-06-22 10:52 (10.1.80.159)
root pts/1 2016-06-22 11:10 (10.1.80.159)
如果我们想提取每一行的第 4 个字节,就这样:1
2
3[[email protected] ~]# who | cut -b 4
t
t
如果我想提取第1、2、4个字节,怎么办?有些面方法可以使用:1
2
3[[email protected] ~]# who | cut -b 1-2,4
rot
rot
类似 “1-2” 这样的小技巧,如下:1
2
3
4
5
6
7[[email protected] ~]# who | cut -b -2,4
rot
rot
[[email protected] ~]# who | cut -b 2-
oot pts/0 2016-06-22 10:52 (10.1.80.159)
oot pts/1 2016-06-22 11:10 (10.1.80.159)
想必你看出来了,-2 表示从第一个字节到第二个字节,2- 表示从第二个字节到行尾。如果你细心,你可以看到这种情况,都包含了第二个字节 “0”。
如果我执行 who | cut -2,2,你觉得会如何呢?答案是输出正行,不会出现连服两个重叠的第二列的情况,看:1
2root pts/0 2016-06-22 10:52 (10.1.80.159)
root pts/1 2016-06-22 11:10 (10.1.80.159)
以字符定位
还是下面的列子:1
2
3[[email protected] ~]# who | cut -c 1-2,4
rot
rot
不过,看着怎么和 -b 没有什么区别。其实不然,看似相同,只是因为这个例子中 who 输出的都是单字节字符,所以用 -b 和 -c 没有区别,去过提取中文效果就出来了。1
2
3
4
5
6
7
8
9
10[email protected] ~]# cat cut_ch.txt
星期一
星期二
[[email protected] ~]# cat cut_ch.txt | cut -b 1
[[email protected] ~]# cat cut_ch.txt | cut -c 1
星
星
看到了吧,以 -c 则会以字符为单位,输出正常;而 -b 只会傻傻的以字节(8位二进制位)来计算,输出就不正常了。
域的概念
刚才提到的 -b 和 -c 只能在固定格式的文档中提取信息,而对于非固定格式的信息则束手无策。这时候域就派上用场了。
以 /etc/password 为例:1
2
3
4
5
6
7
8
9
10
11
12
13[[email protected] ~]# cat /etc/passwd | head -n 5
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
[[email protected] ~]# cat /etc/passwd | head -n 5 | cut -d":" -f 1
root
bin
daemon
adm
lp
看到了吧,用 -d 来设置间隔符为冒号,然后用 -f 来设置我们要取出的第一个域。
当然,在设定 -f 时,也可以使用例如 3-4 或者 4- 类似的格式:1
2
3
4
5
6[[email protected] ~]# cat /etc/passwd | head -n 5 | cut -d":" -f 1,6-7
root:/root:/bin/bash
bin:/bin:/sbin/nologin
daemon:/sbin:/sbin/nologin
adm:/var/adm:/sbin/nologin
lp:/var/spool/lpd:/sbin/nologin