Created
April 17, 2018 16:47
-
-
Save tst2005/63c9376781325012a295a3f3c7436f5c to your computer and use it in GitHub Desktop.
chained grep with friendly syntax
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
#!/bin/sh | |
filters() { | |
if [ $# -le 1 ]; then | |
local grepopt='' | |
case "$1" in | |
('no '?*) set -- "${1#no }"; grepopt='-v' ;; | |
esac | |
case "$1" in | |
(*'=ANY') | |
grep $grepopt -- '\<'"${1%=*}"'=ANY\>'; return $? | |
;; | |
(*'=') | |
grep $grepopt -- '\<'"$1"'.*\>'; return $? | |
;; | |
esac | |
grep $grepopt -- '\<\('"$1"'\|'"${1%=*}"'=ANY\)\>' | |
return $? | |
fi | |
local a1="$1";shift; | |
filters "$a1" | filters "$@" | |
} | |
filters "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment