cut 命令

NAME
    cut -- cut out selected portions of each line of a file

SYNOPSIS
    cut -b list [-n] [file ...]
    cut -c list [file ...]
    cut -f list [-d delim] [-s] [file ...]

  参数:
     -b:以字节为单位进行分割。这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志。
     -c:以字符为单位进行分割。
     -d:自定义分隔符,默认为制表符。
     -f:与-d一起使用,指定显示哪个区域。
     -n:取消分割多字节字符。仅和 -b 标志一起使用。如果字符的最后一个字节落在由 -b 标志的 List 参数指示的<br />范围之内,该字符将被写出;否则,该字符将被排除。

示例:

cut -b 1 passwd //打印第一个字符

cut -c 1-4  passwd  //打印1-4个字符

cut -c 4,6  passwd //打印第4和第6个字符

cut -c 5- passwd //打印5至行末所有字符

cut -c -5 passwd //打印行首的前5个字符

cut -d ":" -f1 passwd //打印以冒号分割的第一栏

cut -d ":" -f1-3 passwd //打印以冒号分割的1-3栏 

原文地址:https://www.cnblogs.com/imcati/p/11619097.html