zoukankan      html  css  js  c++  java
  • linux常用命令 cut字符截取命令

    cut 字符截取

    cut [选项] 文件名

    选项
    -f 列号: 提取第几列
    -d 分割符:按照指定的分隔符分割列
    

    默认使用制表符("tab")进行分割

    ssgao:Downloads aouo$ cut -f 2 ssgao.txt  获取第列
    ssgao
    ssgao:Downloads aouo$ cut -f 2,4 ssgao.txt 获取第4列
    ssgao   37
    

    使用自定义的分割符

    ssgao:Downloads aouo$ cat ssgao.txt 
    name,ssgao,age,37
    ssgao:Downloads aouo$ cut -f 1 -d "," ssgao.txt  #使用","进行分割,并获取第一列,-f和-d的前后顺序可以互换
    name
    ssgao:Downloads aouo$ 
    

    cut命令的缺点

    很复杂的分割,比如df -h 输出的的时候有多个空格
    ssgao:Downloads aouo$ df -h
    Filesystem      Size   Used  Avail Capacity iused      ifree %iused  Mounted on
    /dev/disk1     233Gi   80Gi  153Gi    35% 1054436 4293912843    0%   /
    devfs          182Ki  182Ki    0Bi   100%     631          0  100%   /dev
    map -hosts       0Bi    0Bi    0Bi   100%       0          0  100%   /net
    map auto_home    0Bi    0Bi    0Bi   100%       0          0  100%   /home
    
  • 相关阅读:
    生成器,迭代器
    装饰器
    作业修改配置文件 查询,添加
    continue 和 break的实例
    作业,修改haproxy配置文件
    zabbix分布式部署
    zabbix全网监控介绍
    nginx+tomcat9+memcached-session-manager会话共享
    tomcat管理登陆界面无法进行登陆
    JAVA与tomcat部署
  • 原文地址:https://www.cnblogs.com/ssgao/p/8881887.html
Copyright © 2011-2022 走看看