基本用法
典型用法是使用 CSV 类型的文件,其中每一行由分隔符分隔的字段组成,由选项 -d 指定。默认分隔符是 TAB 字符。假设你有一个数据文件 data.txt,其中包含类似的行
0 0 755 1482941948.8024
102 33 4755 1240562224.3205
1003 1 644 1219943831.2367
然后
# extract the third space-delimited field
$ cut -d ' ' -f3 data.txt
755
4755
644
# extract the second dot-delimited field
$ cut -d. -f2 data.txt
8024
3205
2367
# extract the character range from the 20th through the 25th character
$ cut -c20-25 data.txt
948.80
056222
943831
像往常一样,开关与其参数之间可以有可选空格:-d, 与 -d , 相同
GNU cut 允许指定 --output-delimiter 选项:(此示例的一个独立特性是必须转义分号作为输入分隔符以避免 shell 的特殊处理)
$ cut --output-delimiter=, -d\; -f1,2 <<<"a;b;c;d"
a,b