Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
executable file 32 lines (27 sloc) 954 Bytes
#!/usr/bin/env zsh
# filter show everything between start and end markers, both marker lines are also shown
# ex. __sm.filter.show.group "^#sm start group1$" "^#sm end group1$"
__sm.filter.show.group()
{
awk 'BEGIN{in_group=0} /'"$1"'/ {in_group=1} in_group==1 {print} /'"$2"'/ {in_group=0}'
}
# filter remove everything between start and end markers, both marker lines are also dropped
# ex. __sm.filter.remove.group "^#sm start group1$" "^#sm end group1$"
__sm.filter.remove.group()
{
awk 'BEGIN{in_group=0} /'"$1"'/ {in_group=1} in_group==0 {print} /'"$2"'/ {in_group=0}'
}
# filter show lines matching pattern
# ex. __sm.filter.show.matching "patter with spaces" pattern2
__sm.filter.show.matching()
{
typeset IFS="|"
GREP_OPTIONS="" \grep -E "$*"
}
# filter remove lines matching pattern
# ex. __sm.filter.remove.matching "patter with spaces" pattern2
__sm.filter.remove.matching()
{
typeset IFS="|"
GREP_OPTIONS="" \grep -Ev "$*"
}
Something went wrong with that request. Please try again.