zoukankan      html  css  js  c++  java
  • Linux学习之正则表达式grep

    1. 关键词显示颜色,且加上行号

      dmesg|grep -n --color=auto 'eth'

    2. 将关键词所在行的前2行和后3行,也一起显示

      dmesg|grep -n -A3 -B2 --color=auto 'eth'

    3. 自动将关键词加上颜色

      vim ~/.bashrc

      alias grep='grep --color=auto'

      source ~/.bashrc

    4. 在某个档案中搜索特定字符串

      gerp -n 'the' regular_express.txt

    5. 反向选择,搜索不含特定字符串的行

      grep -vn 'the' regular_express.txt

    6. 不区分大小写搜索特定字符串

    7. grep -

    in 'the' regular_express.txt

    7. 查找test或taste

      grep -n 't[ea]st' regular_express.txt

    8. 不包含某字符

      grep -n '[^g]oo' regular_express.txt

    9. 搜索数字所在行

      grep -n '[0-9]' regular_express.txt

     grep -n '[[:digit:]]' regular_express.txt

    10. ^在[]内代表非,在[]外代表行首

      gerp -n '^the' regular_express.txt(搜索行首是the的行)

     grep -n '^[[:lower:]]' regular_express.txt(搜索行首是小写字母的行)

    11.行尾以小数点.结尾的

     grep -n '.$' regular_express.txt

    12.不要文档中空白行和开头带#的行

     grep -v '^$' /etc/syslog.conf | grep -v '^#'

    13.一定有一个任意字符:.(小数点)

     grep -n 'g..d' regular_express.txt

    14.重复0个或多个前面的字符:*(星号)

     grep -n 'ooo*' regular_express.txt(至少存在2个oo)

    15.找出g开头和g结尾的字符串,当中的字符可有可无

     grep -n 'g.*g' regular_express.txt

    16.限定连续字符范围:{}

    grep -n 'go{2,5}g' regular_express.txt(找出g后面接2到5个o的)

    17.列出etc下的链接档案数量:ll /etc|grep '^l'|wc -l

  • 相关阅读:
    预览PDF【reactpdf】插件的使用(二)
    多叉merkletree的实现
    中国优秀的架构师是不是出现了严重断层?
    工程师的思维转变
    QCore/Library说明文档
    QParserGenerator代码分析二(A fix&An example)
    山寨STL实现之list
    山寨STL实现笔记
    山寨STL实现之内存池V2
    词法分析器1(正则表达式到εNFA的转换)
  • 原文地址:https://www.cnblogs.com/enginex/p/6802708.html
Copyright © 2011-2022 走看看