例1:

 
  
  1. [root@localhost ~]# echo $PATH

  2. /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin


  3. [root@localhost ~]# echo $PATH | cut -d ':' -f1 //显示以":"分隔的第一个区域

  4. /usr/kerberos/sbin

  5. [root@localhost ~]# echo $PATH | cut -d ':' -f1,3 //显示以":"分隔的第一和第三个区域

  6. /usr/kerberos/sbin:/usr/local/sbin

  7. [root@localhost ~]# echo $PATH | cut -d ':' -f1-3 //显示以":"分隔的第一到第三个区域

  8. /usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin


例2:

 
  
  1. [root@localhost ~]# cat export.part  

  2. declare -x SSH_TTY="/dev/pts/1"

  3. declare -x TERM="linux"

  4. declare -x USER="root"

  1. [root@localhost ~]# cat export.part | cut -c 12 //只显示第12个字符

  2. S

  3. T

  4. U

  5. [root@localhost ~]# cat export.part | cut -c -12 //显示行首到第12个字符(包括12)

  6. declare -x S

  7. declare -x T

  8. declare -x U

  9. [root@localhost ~]# cat export.part | cut -c 12- //显示第12个字符到行尾(包括12)

  10. SSH_TTY="/dev/pts/1"

  11. TERM="linux"

  12. USER="root"

例3:


[root@localhost ~]# echo "abcdefg" | cut -c 1,3-5,7

acdeg


注意和head -c的区别……


====================================================


补充:

1、cut -s -f1 1.txt 只处理含有制表符的行

2、cut -d ":" --complement -f1,2 /etc/passwd :补集运算,输出除1和2列之外的列