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. 基于spring boot的统一异常处理

    一.springboot的默认异常处理 Spring Boot提供了一个默认的映射:/error,当处理中抛出异常之后,会转到该请求中处理,并且该请求有一个全局的错误页面用来展示异常内容. 例如这里我 ...

  2. angular2.0学习笔记7.echarts 地图(type:'map')slice undifined 出错问题

    在 项目\node_modules\echarts\lib\chart\map.js文件头部 ... ... require("../coord/geo/geoCreator"); ...

  3. The 10 Best Choices On The Market Review 2018

    Looking to buy a scan tool or considering one of Autel Scanner impressive product line?. The company ...

  4. Linux使用touch批量修改文件/文件夹时间戳

      Linux下touch是一个非常有用的命令. touch语法结构如下: touch [-acfm][-d <日期时间>][-r <参考文件或目录>][-t <日期时间 ...

  5. CF Round #510 (Div. 2)

    前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...

  6. hihoCoder1159 扑克牌

    一道记忆化搜索 原题链接 和着色方案很像,这里就不详细阐述,可以去我博客里的着色方案里看. 但要注意本题不一样的是同种面值的牌花色不同,所以在转移时还需要乘上同种面值的牌的个数. #include&l ...

  7. 全局组建封装(挂载到vue实例的原型中,通过this访问)

    主题:组建的封装  一:install注册的全局封装(v-grid九宫格组建)               1.九宫格的封装主要有三个api 点击功能 每行个数 是否隐藏边框              ...

  8. mysql错误日志

    cat /etc/my.cnf

  9. idea部署tomcat-404错误

    今天在部署数据质量web工程在tomcat后,访问时报404错误,在网上搜了很多相关配置,也都是一步一步来的 Application Context 也配置好了,Artifact也添加了,就是访问不了 ...

  10. OneZero第三周第四次站立会议(2016.4.7)

    1. 时间: 18:35--18:50 共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http: ...