zoukankan      html  css  js  c++  java
  • #每日Linux小练习#03 正则表达式

    正则表达式(Regular Expression ,RE)是处理字符串的方法,它是以为单位来进行字符串的处理行为,

    通过一些特殊符号的辅助,可以让用户轻易达到查找,删除,替换某特定字符串的处理程序。

    #!/bin/bash
    
    if [ $# == 0 ];then
        echo "Please input parameters:"
        echo "dmesg OR txt"
    fi
    
    if [ "$1" == "dmesg" ];then
        dmesg | grep 'eth'
        echo "******************"
        dmesg | grep -A1 -B2 'eth'
        echo "******************"
        dmesg | grep -A1 -B2  -n --color=auto 'eth'
    fi
    
    if [ "$1" == "txt" ];then
        echo "**********************lines with 'the'***********************"
        grep -n --color=auto 'the' ./material/regular_express.txt
        echo "**********************lines without 'the'********************"
        grep -v -n --color=auto 'the' ./material/regular_express.txt
        echo "**********************lines with 'the'(no matter lower or bigger)********************"
        grep -i -n --color=auto 'the' ./material/regular_express.txt
        echo "**********************lines with 't[ae]st'********************"
        grep -n --color=auto 't[ae]st' ./material/regular_express.txt
        echo "**********************lines with 'oo'********************"
        grep -n --color=auto 'oo' ./material/regular_express.txt
        echo "**********************lines without 'oo'starting with g ********************"
        grep -n --color=auto '[^g]oo' ./material/regular_express.txt
        echo "**********************lines without 'oo'starting with a-z ********************"
        grep -n --color=auto '[^a-z]oo' ./material/regular_express.txt
        echo "**********************lines without 'oo'starting with lower ********************"
        grep -n --color=auto '[^[:lower:]]oo' ./material/regular_express.txt
        echo "**********************lines without digit ********************"
        grep -n --color=auto '[^[:digit:]]' ./material/regular_express.txt
        echo "**********************lines starting with 'the' ********************"
        grep -n --color=auto '^the' ./material/regular_express.txt
        echo "**********************lines starting with lower ********************"
        grep -n --color=auto '^[a-z]' ./material/regular_express.txt
        echo "**********************lines not starting with character ********************"
        grep -n --color=auto '^[^a-zA-Z]' ./material/regular_express.txt
        echo "**********************lines ending with '.' ********************"
        grep -n --color=auto '.$' ./material/regular_express.txt
        echo "**********************display lines which are not empty and not begining with #  ********************"
        grep -v -n --color=auto '^$' ./material/regular_express.txt | grep -v -n '^#'
        echo "**********************lines with g..d  ********************"
        grep -n --color=auto 'g..d' ./material/regular_express.txt
        echo "**********************lines with no less than 2 oo (* means 0 or more) ********************"
        grep -n --color=auto 'ooo*' ./material/regular_express.txt 
        echo "**********************lines with string which begins with g and ends with g********************"
        grep -n --color=auto 'g.*g' ./material/regular_express.txt 
        echo "**********************lines with 2-5 o in go..g ********************"
        grep -n --color=auto 'go{2,5}g' ./material/regular_express.txt 
        echo "**********************lines with 2 o in go..g ********************"
        grep -n --color=auto 'go{2}g' ./material/regular_express.txt 
        echo "**********************lines with 2 or more o in go..g ********************"
        grep -n --color=auto 'go{2,}g' ./material/regular_express.txt 
    fi
  • 相关阅读:
    select/poll/epoll 对比
    I/O Mutiplexing poll 和 epoll
    Socket 编程IO Multiplexing
    ubuntu12.04 lts 安装gcc 4.8
    time since epoch
    ceph-RGW Jewel版新概念
    支持向量机(svm)
    MachineLearning之Logistic回归
    ML之回归
    ML之监督学习算法之分类算法一 ——— 决策树算法
  • 原文地址:https://www.cnblogs.com/wuqi/p/4709555.html
Copyright © 2011-2022 走看看