zoukankan      html  css  js  c++  java
  • Linux grep 命令实例

    # vim test2.txt
    Christian Scott lives here and will put on a Christmas party.
    There are around 30 to 35 people invited.
    They are:
     Tom
    Dan
    Rhonda Savage
    Nicky and Kimerly.
    Steve, Suzanne, Ginger and Larry.
    

    大写字母开头,总长度为3位。

    # cat test2.txt | grep '^[A-Z]..$'
    Dan
    

    空格开头,第一个字母大写字母开头,总长度为3位。

    # cat test2.txt | grep '^ [A-Z]..$'
    Tom
    

    大写字母开头,包含数字:

    # cat test2.txt | grep '^[A-Z]*.*[0-9]'
    There are around 30 to 35 people invited.
    

    大小写字母开头,包含逗号:

    # cat test2.txt | grep '^[A-Za-z]*.*[,][A-Za-z]*.*$'
    Steve, Suzanne, Ginger and Larry.
    

    目录中以z开头的文件:

    # ls -l /bin/ | grep '[0-9] z[a-z]*.*$'
    # ls /bin/ | grep '^z'
    

    目录中不包含大写字母A-Y,小写字母a-Y及数字0-9的文件:

    # ls /bin/ | grep '^[^A-Ya-y0-9]'
    

    目录中以x或者z开头的文件:

    # ls /bin/ | grep '^[xz]'
    

    目录中包含8或者6的文件:

    # ls /bin/ | grep '[86]'

    目录中以gc开头,长度为3个字符的文件:

    # ls /bin/bash | grep '^gc.$'
    gcc
    

    目录中以op结尾,长度为4个字符的文件  

    # ls /bin/bash | grep '^..op$'
    htop
    

    目录中以z开头,h结尾,长度为3个字符的文件:

    # ls /bin/bash | grep '^z.h$'
    zsh
    

    目录中以t开头,e或者p结尾,长度为3个字符的文件:  

    # ls /bin/bash | grep '^to[ep]'
    toe
    top
    

    目录中以t开头,以数字6结尾的文件:

    # ls | grep '^t[a-z]*6$'
    tracepath6
    traceroute6
    

     

    [THE END] 

  • 相关阅读:
    C#之泛型
    etcd 使用: golang 例子
    九卷读书:《高效能人士的7个习惯》脑图
    Go package(2) strings 用法
    技术管理:技术管理者的多维度能力及成长路径
    gin框架教程:代码系列demo地址
    五大常见的MySQL高可用方案
    gin框架教程三:JWT的使用
    九卷读书:商业模式画布
    Go package(1) time 用法
  • 原文地址:https://www.cnblogs.com/configure/p/14973834.html
Copyright © 2011-2022 走看看