• grep/awk/sed 或者 并且 否定


    Grep 'OR' Operator  grep 与“或”一起用

    Find all the lines in a file, that match any of the following patterns.

    Using GREP command :

    grep "pattern1|pattern2" file.txt
    grep -E "pattern1|pattern2" file.txt
    grep -e pattern1 -e pattern2 file.txt
    egrep "pattern1|pattern2" file.txt

    Using AWK command :

    awk '/pattern1|pattern2/' file.txt

    Using SED command :

    sed -e '/pattern1/b' -e '/pattern2/b' -e d file.txt



    Grep 'AND' Operator grep 与“与”一起用

    Find and print all the lines in a file, that match multiple patterns.

    Using GREP command :

    grep -E 'pattern1.*pattern2' file.txt # in that order
    grep -E 'pattern1.*pattern2|pattern2.*pattern1' file.txt # in any order
    grep 'pattern1' file.txt | grep 'pattern2' # in any order

    Using AWK command :

    awk '/pattern1.*pattern2/' file.txt # in that order
    awk '/pattern1/ && /pattern2/' file.txt # in any order

    Using SED command :

    sed '/pattern1.*pattern2/!d' file.txt # in that order
    sed '/pattern1/!d; /pattern2/!d' file.txt # in any order



    Grep 'NOT' Operator grep 与“非”一起用

    Find and print all the lines, that do not match a pattern.

    Using GREP command :

    grep -v 'pattern1' file.txt

    Using AWK command :

    awk '!/pattern1/' file.txt

    Using SED command :

    sed -n '/pattern1/!p' file.txt

  • 相关阅读:
    设计模式之桥接模式
    设计模式之适配器模式
    设计模式之建造者模式
    设计模式之原型设计
    Exception in thread "main" java.lang.UnsupportedOperationException
    设计模式7大原则
    设计模式之单例模式
    初识python
    消息传递:发布订阅模式详解
    哨兵机制(Redis Sentinel)
  • 原文地址:https://www.cnblogs.com/emanlee/p/3833702.html
Copyright © 2020-2023  润新知