zoukankan      html  css  js  c++  java
  • cut命令

    例1

    $ cat test1
    abcdefg
    hijklmn
    opq
    rst
    uvw
    xyz
    $ cut test1 -c 1
    a
    h
    o
    r
    u
    x
    $ cut test1 -c 2,4-6
    bdef
    iklm
    p
    s
    v
    y
    $ cut test1 -c -4
    abcd
    hijk
    opq
    rst
    uvw
    xyz
    $ cut test1 -c 3-
    cdefg
    jklmn
    q
    t
    w
    z
    $ cut test1 -c -3,3-
    abcdefg
    hijklmn
    opq
    rst
    uvw
    xyz

    例2

    $ cat test2
    星期一
    星期二
    星期三
    $ cut test2 -c 3
    一
    二
    三
    $ cut test2 -b 3
    �
    �
    �

    汉字是utf8编码,3字节

    $ cut test2 -nb 9
    一
    二
    三

    例3

    $ cat /etc/passwd | tail -n 5
    postfix:x:89:89::/var/spool/postfix:/sbin/nologin
    apache:x:48:48:Apache:/var/www:/sbin/nologin
    icecream:x:992:987:Icecream Daemon:/var/cache/icecream:/bin/false
    mysql:x:27:27:MySQL Server:/var/lib/mysql:/bin/bash
    news:x:9:13:news user:/:/sbin/nologin
    $ cat /etc/passwd | tail -n 5 | cut -d : -f 1
    postfix
    apache
    icecream
    mysql
    news
    $ cat /etc/passwd | tail -n 5 | cut -d ' ' -f 1
    postfix:x:89:89::/var/spool/postfix:/sbin/nologin
    apache:x:48:48:Apache:/var/www:/sbin/nologin
    icecream:x:992:987:Icecream
    mysql:x:27:27:MySQL
    news:x:9:13:news

    省略-d表示以 分隔

  • 相关阅读:
    装饰器和表达生成式
    函数
    字符编码
    函数基础
    列表,字典与集合
    Linux Semaphore
    tp5安装easyWeChat
    wx.request
    小程序设计规范
    小程序的概念和特点
  • 原文地址:https://www.cnblogs.com/chenkkkabc/p/3300992.html
Copyright © 2011-2022 走看看