shell 的cut 命令用法
来源:互联网 发布:小米盒子看网络电视吗 编辑:程序博客网 时间:2024/05/13 07:08
原帖地址 : http://blog.csdn.net/arkblue/article/details/8507989
shell 的cut 命令用法
分类: Linux shell2013-01-16 09:41 393人阅读 评论(0) 收藏 举报
和awk差不多的功能
例1
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -d : -f 1,5`
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- root:root
例 2,只打印第一个字段field
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -d : -f 1`
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- root
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -d : -f 1-`
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- root:x:0:0:root:/root:/bin/bash
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -d : -f 3-` // 打印第3个字段后的所有字段,包含第三个字段
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- 0:0:root:/root:/bin/bash
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -d : -f 2-4`
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- x:0:0
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -c 2-5 ` // 截取第2到第5个字符
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- oot:
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -c 2-7 ` // 截取第2到第7个字符
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- oot:x:
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -c -2 ` // 截取前两个字符
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- ro
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ a=`echo root:x:0:0:root:/root:/bin/bash | cut -c 2- ` // 截取第2个以后的
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ echo $a
- oot:x:0:0:root:/root:/bin/bash
例 6 指定文件,最后一个参数是文件名
- $ cat pass.txt
- root:x:0:0:root:/root:/bin/bash
- bin:x:1:1:bin:/bin:/sbin/nologin
- daemon:x:2:2:daemon:/sbin:/sbin/nologin
- adm:x:3:4:adm:/var/adm:/sbin/nologin
- shuohailhl@shuohailhl-PC /cygdrive/d
- $ cut -d : -f 1-3 ./pass.txt
- root:x:0
- bin:x:1
- daemon:x:2
- adm:x:3
- shell 的cut 命令用法
- shell 的cut 命令用法
- shell 的cut 命令用法
- shell - cut的用法
- linux shell cut 命令用法
- linux shell cut命令用法
- cut 命令的用法
- cut命令的用法
- shell中head cut readelf命令的用法
- shell中cut的用法
- 【shell】cut命令及常见用法
- cut命令的详细用法
- shell编程中cut的用法
- shell脚本编程---cut的一个用法
- linux命令之cut命令的用法
- shell中很强大的cut命令
- shell中cut命令的使用方法
- shell的字符串截取命令cut
- hdu 2710 Max Factor
- ubuntu12.04samba服务器配置
- MD5+ENUM DEMO
- C#获取网页源码
- 使用Gradle快速构建Java项目
- shell 的cut 命令用法
- 黑马程序员_java编程基础第3天1-5 循环结构while;do while;for
- 小思考
- 18.C++构造函数的重载
- memcached 高可用工具 memcached-ha
- PE文件详解------PE文件结构剖析
- 转)计算机领域的顶级会议和期刊
- mvc 从后台得到前台元素值的方法
- java对byte数组解压缩(zip,gzip,bzip2,jzlib)