博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Filtering Specific Columns with cut
阅读量:7290 次
发布时间:2019-06-30

本文共 2079 字,大约阅读时间需要 6 分钟。

  Filtering Specific Columns with cut  

  When working with text files, it can be useful to filter out specific fields. Imagine that you need to see a list of all users in the /etc/passwd file. In this file, several fields are defined, of which the first contains the name of the users who are defined. To filter out a specific field, the  cut  command is useful. To do this, use the  -d  option to specify the field delimiter(-d参数指定分隔符) followed by  -f  with the number of the specific field you want to filter out(-f参数指出你要过滤哪一个fields). So, the complete command is  cut -d : -f 1 /etc/passwd  if you want to filter out  the first field of the /etc/passwd file. You can see the result bellow:

[root@rhel7 ~]# cat /etc/passwdroot:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinoperator:x:11:0:operator:/root:/sbin/nologingames:x:12:100:games:/usr/games:/sbin/nologinftp:x:14:50:FTP User:/var/ftp:/sbin/nologinnobody:x:99:99:Nobody:/:/sbin/nologinavahi-autoipd:x:170:170:Avahi IPv4LL Stack:/var/lib/avahi-autoipd:/sbin/nologinsystemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologinsystemd-network:x:998:996:systemd Network Management:/:/sbin/nologindbus:x:81:81:System message bus:/:/sbin/nologinpolkitd:x:997:995:User for polkitd:/:/sbin/nologintss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologinpostfix:x:89:89::/var/spool/postfix:/sbin/nologinsshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologinrusky:x:1000:1000:rusky:/home/rusky:/bin/bash[root@rhel7 ~]# cut -d : -f 1 /etc/passwd   --以冒号为分隔,filter第一部分rootbindaemonadmlpsyncshutdownhaltmailoperatorgamesftpnobodyavahi-autoipdsystemd-bus-proxysystemd-networkdbuspolkitdtsspostfixsshdrusky[root@rhel7 ~]#

 或者以冒号为分隔,filter第二部分结果如下:

[root@rhel7 ~]# cut -d : -f 2 /etc/passwd  xxxxxxxxxxxxxxxxxxxxxx

 

转载地址:http://kycjm.baihongyu.com/

你可能感兴趣的文章
Sedona NetFusion 在OIF/ONF T-API 互通测试中扮演关键角色
查看>>
Linux中命令链接操作符的十个最佳实例
查看>>
Linux下常用的shell命令记录
查看>>
想转行投身云计算?推荐四个职业方向供你参考
查看>>
Windows下搭建Mantis详解
查看>>
性能测试—性能环境与数据
查看>>
《Web测试囧事》——1.11 IE 9不支持占位符导致搜索行为异常
查看>>
《网络安全原理与实践》一1.4 风险评估
查看>>
《Android群英传》读书笔记
查看>>
HTC VR 空间追踪系统开源:开发第三方 VR 硬件更容易了
查看>>
Linux DNS解析异常的排查
查看>>
《OpenGL ES应用开发实践指南:Android卷》—— 1.4 创建Renderer类
查看>>
《实施Cisco统一通信VoIP和QoS(CVOICE)学习指南(第4版)》一1.3 配置语音接口...
查看>>
【友盟+】COO叶谦:解读全域大数据战略背后的技术演进
查看>>
《异构信息网络挖掘: 原理和方法(1)》一1.3 本书的内容组织
查看>>
《MATLAB图像处理超级学习手册》一一2.2 矩阵的拼接
查看>>
《精通SNMP》——第1章 SNMP基础1.1 网络管理和SNMP
查看>>
Microsoft.com 20 岁了 历年改版回顾
查看>>
《CUDA C编程权威指南》——1.6 习题
查看>>
《实施Cisco统一通信VoIP和QoS(CVOICE)学习指南(第4版)》一1.2 语音网关如何路由呼叫...
查看>>