一、作用

  1. 按列提取文件内容,文件内容查看,显示行中的指定部分,删除文件中指定字段

二、选项

  • -b 显示指定的字节内容
  • -c 统计字节数
  • -f 按照字段选取
  • -d参数用于设置间隔符号,-f参数用于设置需要看的列数 # -d与-f参数要一块使用

[空格也算一个字节]

三、实例

[root@localhost ~]# who |cut -b 1-4 |uniq 
root
[root@localhost ~]# who |cut -b 1-3 |uniq 
roo
[root@localhost ~]# who |cut -b 1- |uniq 
root     tty1         2022-06-17 20:24
root     pts/2        2022-06-17 20:25 (192.168.11.254)
[root@localhost ~]# who |cut -b 5- |uniq 
     tty1         2022-06-17 20:24
     pts/2        2022-06-17 20:25 (192.168.11.254)
[root@localhost ~]# who
root     tty1         2022-06-17 20:24
root     pts/2        2022-06-17 20:25 (192.168.11.254)
[root@localhost ~]# who |cut -c 1-3,10
root
roop
[root@localhost ~]# cat  /work/1.sh 
#!/bin/bash
sum=0  #全局变量
function getsum(){
    for((i=$1; i<=$2; i++)); do
        ((sum+=i))  #改变全局变量
    done
    return $?  #返回上一条命令的退出状态
}
read m
read n
if getsum $m $n; then
    echo "The sum is $sum"  #输出全局变量
else
    echo "Error!"
fi
[root@localhost ~]# cut -do -f 2  /work/1.sh 
#!/bin/bash
sum=0  #全局变量
n getsum(){
r((i=$1; i<=$2; i++)); d
        ((sum+=i))  #改变全局变量
ne
    return $?  #返回上一条命令的退出状态
}
read m
read n
if getsum $m $n; then
 "The sum is $sum"  #输出全局变量
else
 "Err
fi