cut

cut的工作就是“剪”,具体说就是在文件中负责剪切数据用的。cut命令从文件的每一行剪切字节、字符、和字段并将这些字节、字符和字段输出

基本用法

cut [参数] filename
# 说明:默认分割符是制表符

参数说明

选项参数 功能
-f 列号,提取第几列
-d 分隔符,按照指定分隔符分割列

案例实操

数据准备

[root@slave2 testshell]# touch cut.txt
[root@slave2 testshell]# vim cut.txt
dong shen
guan zhen
wo wo
lai lai
le le

切割cut.txt第一列

[root@slave2 testshell]# cut -d " " -f  cut.txt
dong
guan
wo
lai
le

切割cut.txt第二、三列

[root@slave2 testshell]# vim cut.txt
dong shen si
guan zhen chuan
wo wo wo
lai lai lai
le le le
[root@slave2 testshell]# cut -d " " -f , cut.txt
shen si
zhen chuan
wo wo
lai lai
le le

在cut.txt文件中切割出guan

[root@slave2 testshell]# cat cut.txt | grep ^guan
guan zhen chuan
[root@slave2 testshell]# cat cut.txt | grep ^guan | cut -d " " -f
guan

选取系统PATH变量值,第二个“:”开始后的所有路径

[root@slave2 testshell]# echo $PATH
/usr/local/src/kafka_2.-0.10.2.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/src/scala-2.11./bin:/usr/local/src/spark-2.1.-bin-hadoop2./bin:/usr/local/src/jdk1..0_171/bin:/usr/local/src/hadoop-2.6./bin:/usr/local/src/zookeeper-3.4./bin:/root/bin
[root@slave2 testshell]# echo $PATH | cut -d : -f -
/usr/local/bin:/usr/sbin:/usr/bin:/usr/local/src/scala-2.11./bin:/usr/local/src/spark-2.1.-bin-hadoop2./bin:/usr/local/src/jdk1..0_171/bin:/usr/local/src/hadoop-2.6./bin:/usr/local/src/zookeeper-3.4./bin:/root/bin

切割ipconfig后打印的IP地址

[root@slave2 testshell]# ifconfig
ens33: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
inet 192.168.242.22 netmask 255.255.255.0 broadcast 192.168.242.255
inet6 fe80::c2d4::9c7c:ca0b prefixlen scopeid 0x20<link>
ether :0c:::af:c5 txqueuelen (Ethernet)
RX packets bytes (1.9 GiB)
RX errors dropped overruns frame
TX packets bytes (282.1 MiB)
TX errors dropped overruns carrier collisions lo: flags=<UP,LOOPBACK,RUNNING> mtu
inet 127.0.0.1 netmask 255.0.0.0
inet6 :: prefixlen scopeid 0x10<host>
loop txqueuelen (Local Loopback)
RX packets bytes (273.3 MiB)
RX errors dropped overruns frame
TX packets bytes (273.3 MiB)
TX errors dropped overruns carrier collisions
[root@slave2 testshell]# ifconfig ens33
ens33: flags=<UP,BROADCAST,RUNNING,MULTICAST> mtu
inet 192.168.242.22 netmask 255.255.255.0 broadcast 192.168.242.255
inet6 fe80::c2d4::9c7c:ca0b prefixlen scopeid 0x20<link>
ether :0c:::af:c5 txqueuelen (Ethernet)
RX packets bytes (1.9 GiB)
RX errors dropped overruns frame
TX packets bytes (282.2 MiB)
TX errors dropped overruns carrier collisions [root@slave2 testshell]# ifconfig ens33 | grep "inet "
inet 192.168.242.22 netmask 255.255.255.0 broadcast 192.168.242.255
[root@slave2 testshell]# ifconfig ens33 | grep "inet " | cut -d " " -f
192.168.242.2

shell工具-cut的更多相关文章

  1. Shell工具| 流程控制

    1. 流程控制 if 判断 ()[ 条件判断式 ],中括号和条件判断式之间必须有空格 ()if后要有空格 [kris@hadoop datas]$ vim if.sh #!/bin/bash -eq ...

  2. Shell 脚本(五) Shell 工具 及 企业面试题

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 十.Shell工具(重点) 1.cut cut 的工作就是“剪”,具体的说就是在文件中负责剪切数据用的. ...

  3. linux shell工具集合

    1)判断进程是否存在,如果不存在再执行启动命令,可以避免一个脚本同时启动多份 if [ $(ps -ef |grep  bastion_account.sh|grep -v grep|wc -l) - ...

  4. 两个有用的shell工具总结

    shell工具之一:sed sed基础 sed编辑器被称作流编辑器,与常见的交互式文本编辑器刚好相反.文本编辑器可以通过键盘来交互式地插入.删除.替换文本中的数据:而流编辑器是基于一组预先的规则来编辑 ...

  5. 一款值得推荐的shell工具

    1. 一款比较出色的shell工具 熟练的运用shell语言可以提高我们的工作效率,而一款好的shell工具能提高学习的效率,fish shell就是这样一款工具.并且是一款跨平台的工具, 同时可以在 ...

  6. 基于.htaccess的Web Shell工具htshells

    基于.htaccess的Web Shell工具htshells   .htaccess文件是Apache服务器的配置文件.它负责相关目录下的网页配置.一旦用户获得修改该文件的权限,就可以基于该文件构建 ...

  7. ipython是python的交互式shell工具

    ipython: 是python的交互式shell工具,比默认的python shell工具要好用.支持变了自动补全,自动缩进,内置了很多的功能和函数 启动:可以通过cmd来启动该工具 自动补全: I ...

  8. 二、hbase shell工具

    hbase单节点安装请参考: https://www.cnblogs.com/lay2017/p/9944387.html 下文演示hbase shell工具常用的命令,首先启动hbase以及进入sh ...

  9. Linux 一款免费的shell工具 MobaXterm_Personal

    一款免费的shell工具 MobaXterm_Personal

随机推荐

  1. PHP Jquery 代码操作 内容 属性 样式 事件 Json数据

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. iOS.Objective-C.Dependency.Graphing-v0.1

    当Project越来越复杂,模块间的依赖就会很复杂,不合理的依赖就出现:不必要的依赖,双向依赖等等. 在iOS Application Project中可以将依赖定义为:对某个头文件的import. ...

  3. Jenkins2.0中的pipeline

    jenkins的实现是标准的master/slave模式,用户与master交互,master将job分布到slave上运行. jenkins的基本概念: 1. master, 也就是jenkins的 ...

  4. linux- Fedora25 下 解决anacondas3 与ibus冲突问题

    问题:当我们安装了anaconda3之后,会发现ibus-setup进不去. 原因: 是因为ibus-setup的python应该使用python2. 而当我们安装了anaconda3之后,调用pyt ...

  5. activiti5.22整合modeler时出错TypeError: Cannot read property 'split' of undefined

    activiti5.22.0整合modeler时,打开的流程页面不显示工具栏和左边的控件栏,产生如下的错误: TypeError: Cannot read property 'split' of un ...

  6. java8 forEach Map List[转载]

    java8 forEach 在Map和List中的使用 原始的使用 Map<String, Integer> items = new HashMap<>(); items.pu ...

  7. 为什么要使用日志管理?syslog和Windows事件日志

    为什么要使用日志管理?syslog和Windows事件日志 日志管理 - 确保网络安全的先决条件 日志给予您有关网络活动的第一手信息.日志管理确保日志中隐藏的网络活动数据转换为有意义的可操作的安全信息 ...

  8. 784. Letter Case Permutation

    这个题的思想很重要,两种方法 第一种,回溯法 class Solution { public: int sz; vector<string> letterCasePermutation(s ...

  9. 697. Degree of an Array

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  10. 2019.01.22 uoj#14. 【UER #1】DZY Loves Graph(并查集)

    传送门 题意简述: 要求支持以下操作: 在a与b之间连一条长度为i的边(i是操作编号):删除当前图中边权最大的k条边:表示撤销第 i−1次操作,保证第1次,第i−1 次不是撤回操作. 要求在每次操作后 ...