zoukankan      html  css  js  c++  java
  • grep

    扩展grep(grep -E 或者 egrep):
    使用扩展grep的主要好处是增加了额外的正则表达式元字符集。

    打印所有包含NW或EA的行。如果不是使用egrep,而是grep,将不会有结果查出。

        # egrep 'NW|EA' testfile     
        northwest       NW      Charles Main        3.0     .98     3       34
        eastern         EA      TB Savage           4.4     .84     5       20

    对于标准grep,如果在扩展元字符前面加,grep会自动启用扩展选项-E。

    #grep 'NW|EA' testfile
    northwest       NW      Charles Main        3.0     .98     3       34
    eastern         EA      TB Savage           4.4     .84     5       20

    搜索所有包含一个或多个3的行。

    复制代码
    # egrep '3+' testfile
    # grep -E '3+' testfile
    # grep '3+' testfile        
    #这3条命令将会
    northwest       NW      Charles Main          3.0     .98     3       34
    western         WE      Sharon Gray           5.3     .97     5       23
    northeast       NE      AM Main Jr.           5.1     .94     3       13
    central         CT      Ann Stephens          5.7     .94     5       13
    复制代码

    搜索所有包含0个或1个小数点字符的行。
        

    复制代码
    # egrep '2.?[0-9]' testfile 
    # grep -E '2.?[0-9]' testfile
    # grep '2.?[0-9]' testfile 
    #首先含有2字符,其后紧跟着0个或1个点,后面再是0和9之间的数字。
    western         WE       Sharon Gray          5.3     .97     5       23
    southwest       SW      Lewis Dalsass         2.7     .8      2       18
    eastern         EA       TB Savage             4.4     .84     5       20
    复制代码

    搜索一个或者多个连续的no的行。
        

    # egrep '(no)+' testfile
    # grep -E '(no)+' testfile
    # grep '(no)+' testfile   #3个命令返回相同结果,
    northwest       NW      Charles Main        3.0     .98     3       34
    northeast       NE       AM Main Jr.        5.1     .94     3       13
    north           NO      Margot Weber        4.5     .89     5       9

    不使用正则表达式

    fgrep 查询速度比grep命令快,但是不够灵活:它只能找固定的文本,而不是规则表达式。

    如果你想在一个文件或者输出中找到包含星号字符的行

    fgrep  '*' /etc/profile
    for i in /etc/profile.d/*.sh ; do
    
    或
    grep -F '*' /etc/profile
    for i in /etc/profile.d/*.sh ; do
  • 相关阅读:
    Eclipse插件大全 (下)
    Eclipse插件大全 (上)
    Struts2学习笔记
    DisplayTag应用指南
    JFreeChart 2
    JFreeChart 1
    一对一直播app源码开发,多媒体消息发送优化方案
    仿比心视频聊天源码开发,网络节点数量和时延的关系
    一对一直播源码开发,保证实时性要从降低延迟下手
    小视频app源码凭什么成功出圈,守“江山”有多难?
  • 原文地址:https://www.cnblogs.com/gaoxianzhi/p/3214382.html
Copyright © 2011-2022 走看看