Linux之cut命令

cut

  参数:

    -d  指定分隔符,与-f 一起使用,默认是空格。例如:-d“|”

    -f  指定取第几段的数据与-d一起使用

    -c  以字符为单位取出固定字符区间

示例:

取不连续区间的内容的时候使用“,”隔开
[root@BASE test]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@BASE test]# echo $PATH|cut -d":" -f1 /usr/local/sbin [root@BASE test]# echo $PATH|cut -d":" -f1,2 /usr/local/sbin:/usr/local/bin [root@BASE test]# echo $PATH|cut -d":" -f1-3 /usr/local/sbin:/usr/local/bin:/sbin [root@BASE test]# echo $PATH|cut -d":" -f3- /sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@BASE test]# echo $PATH|cut -d":" -f-2 /usr/local/sbin:/usr/local/bin [root@BASE test]# echo $PATH|cut -c -4 /usr [root@BASE test]# echo $PATH|cut -c 1-4 /usr [root@BASE test]# echo $PATH|cut -c 10- l/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin [root@BASE test]# echo $PATH|cut -c 1,2 /u [root@BASE test]# echo $PATH|cut -c 1,4 /r [root@BASE test]# echo $PATH|cut -c 1,4 4-6 cut: 4-6: No such file or directory [root@BASE test]# echo $PATH|cut -c 1,4,4-6 /r/l [root@BASE test]# echo $PATH|cut -c 1,5,6-10 //local [root@BASE test]#
原文地址:https://www.cnblogs.com/along1226/p/4967383.html