Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.