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 \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地址;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值