• 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] 

  • 相关阅读:
    Ubuntu(Linux) + mono + jexus +asp.net MVC3 部署
    爬虫代理
    爬取文件时,对已经操作过的URL进行过滤
    Scrapy项目创建以及目录详情
    Scrapy 框架 安装
    爬虫案例
    爬虫基础以及 re,BeatifulSoup,requests模块使用
    Django_Admin操作
    django 权限管理permission
    Node--01
  • 原文地址:https://www.cnblogs.com/configure/p/14973834.html
Copyright © 2020-2023  润新知