29、linux shell常用的几个函数,cut

1、说明

cut [option] files

cut -d'分隔字元' -f fields

取出分字段的文件的某些特定字段

2、options

-d:用来定义分隔符,默认为tab键,与-f一起使用

-f:需要取得哪个字段,根据-d的分隔字段

-c:以字符 (characters) 为單位取出固定字元區間;-c后面的值指定从第几个字符开始输出。

-c 和 -f 参数可以跟以下子参数:

N 第N个字符或字段

N- 从第一个字符或字段到文件结束

N-M 从第N个到第M个字符或字段

-M 从第一个到第M个字符或字段

3、示例

echo $PATH | cut -d: -f 3,5 //取出第3行和第5

last | cut -d ' '  -f 1

last | cut -c  9-15

last | cut -c  9-

last | cut -d " " -f 1 | sort | uniq

last | cut -d " " -f 1 | sort | uniq -c

参考

1http://doc.linuxpk.com/425.html

2http://linux.vbird.org/linux_basic/0320bash.php#split

原文地址:https://www.cnblogs.com/mydomain/p/2191508.html