zoukankan      html  css  js  c++  java
  • 012_egrep

    1. Basic grammar
        egrep = grep -E
        egrep [OPTIONS] PATTERN [FILE...]
    2. Meta-charecter of extended regexp
        2.1 Character match
            .:  Matchs any single character
            []: Matchs any single character within specified range
            [^]:Matchs any signal character without specified range
        2.2 Matched number
            *:Matchs The preceding item zero or more times, refers to only times.
            .* : Matchs any item -----Any character of any length
            ? : Matchs the preceding item zero or at most one times.
            + : Matchs the preceding item at lest one times.
            {m} : The preceding item is matched exactly m times
            {m,n} : The preceding item is matched at lest m times and at most n times.
            {0,n} : he preceding item is matched at most n times
            {m,} : he preceding item is matched at lest m times
        2.3 Anchoring
            ^ : Only matchs the PATTERN at the begining of a line.
            $ : Only matchs the PATTERN at the end of a line.
            ^PATTERN$ : Matchs the entire line.
            ^$ : Matchs blank lines
            ^[[:space:]]*$ : Matchs blank lines
                
            < or :Matchs at the beginning of a word
            > or :Matchs at the end of a word
            <PATTERN>:Matchs the entire word
        2.4 group
            () : (xy)*ab  --  Matchs 'xy' zero or more times.
        2.5 reference : The same grammar as grep.
    3. Exercise :
        1) Print the default shell and UID of the root/centos/user1 user
            # grep -E '^(root|centos|user1)>' /etc/passwd | cut -d: -f1,3,7
        2) Print the lines which have a word following with parentheses.
            # grep -E -o "^[_[:alpha:]]+()" /etc/rc.d/init.d/functions
        3) echo an absolute path and print its base name with egrep;
            # echo "/mnt/sdc" | grep -E -o "[^/]+/?$" | cut -d"/" -f1
            further:print the directory of the path,just like the result of command dirname
        4) find values between 1-255 of the result of command ifconfig 找出ifconfig命令结果中1-255之间的数值;
        5) 找出ifconfig命令结果中的IP地址;

  • 相关阅读:
    pig中将两列合并为一列:concat
    最小二乘法拟合二元多次曲线
    动态重新加载Class机制之代码测试
    從 Windows Form ComboBox、ListBox 或 CheckedListBox 控制項加入或移除項目
    C#控件一览表
    C#中combobox 和TreeView控件属性、事件、方法收集
    PHP 分页类 潇湘博客
    一个房屋中介业务建模的实例分析
    使用Limit参数优化MySQL查询 潇湘博客
    word中的字号与实际的字体大小一一对应的关系
  • 原文地址:https://www.cnblogs.com/liujun5319/p/9600880.html
Copyright © 2011-2022 走看看