egrep_什么是EGR[通俗易懂]

egrep_什么是EGR[通俗易懂]1.Basicgrammaregrep=grep-Eegrep[OPTIONS]PATTERN[FILE…]2.Meta-charecterofextendedregexp2.1Charactermatch.:M

egrep_什么是EGR[通俗易懂]

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 \b:Matchs at the beginning of a word
        \> or \b: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地址;

今天的文章egrep_什么是EGR[通俗易懂]分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/71899.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注