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. (转)DataRow的各种状态和DataView的两种过滤属性

    DataRow的各种状态 http://www.cnblogs.com/zxjyuan/archive/2008/08/20/1271987.html 一个DataRow对象刚被创建之后(DataTa ...

  2. 转easyui datagrid 前台分页的实现

    easyui datagrid 前台分页的实现java采用的版本 来源:本站原创 js知识 超过5,090人围观 暂无评论 使用easyui分页,有后台服务器端实现和前台浏览器端实现.服务器端实现按规 ...

  3. (转)ScriptManager.RegisterStartupScript方法和Page.ClientScript.RegisterStartupScript() 方法

    ScriptManager.RegisterStartupScript方法 如果页面中不用Ajax,cs中运行某段js代码方式可以是: Page.ClientScript.RegisterStartu ...

  4. python爬虫 urllib库基本使用

    以下内容均为python3.6.*代码 学习爬虫,首先有学会使用urllib库,这个库可以方便的使我们解析网页的内容,本篇讲一下它的基本用法 解析网页 #导入urllib from urllib im ...

  5. python 计时程序运行时间

    import time time_start=time.time() time_end=time.time() print('totally cost',time_end-time_start)

  6. MySQL连接、登录、密码等

    官方教程:https://dev.mysql.com/doc/refman/8.0/en/ 链接数据库,通过指定 -h 参数可以连接网络上的数据库 mysql -u 用户名 -h 服务器IP -P 端 ...

  7. solr搜索配置权重

    配置权重 <requestHandler name="/browse" class="solr.SearchHandler" default=" ...

  8. openssl RSA基本加密解密

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <openssl/bn ...

  9. barcode(index)

    在很多情况下,我们需要把多个样本混合在一起,在同一个通道(lane)里完成测序.像转录组测序.miRNA测序.lncRNA测序.ChIP测序等等,通常每个样本所需要的数据量都比较少,远少于HiSeq一 ...

  10. GG镜像导航

    供程序员使用. http://dir.scmor.com/google/