Created
January 23, 2019 13:40
-
-
Save maoshuai/33113ac457aca7869171942c696f46d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
full_grep() | |
{ | |
# keyword to search | |
local keyword=$1 | |
# mark the actual new line, in this job, it is always a date | |
local newLinePattern="^[0-9]{2}\/[0-9]{2}\/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}" | |
cat | awk ' | |
BEGIN{ | |
isFound = "no" | |
} | |
# match lines with keyword | |
{ | |
# if match print the line | |
if($0~/'"$keyword"'/) | |
{ | |
print $0 | |
isFound="yes" | |
} | |
# if new line begin, flush the flag | |
else if($0~/'"$newLinePattern"'/) | |
{ | |
isFound="no" | |
} | |
# if isFound, print continuely | |
else if(isFound=="yes") | |
{ | |
print $0 | |
} | |
} | |
' | |
} | |
full_grep $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment