Skip to content

Instantly share code, notes, and snippets.

@tst2005
Created April 17, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tst2005/63c9376781325012a295a3f3c7436f5c to your computer and use it in GitHub Desktop.
Save tst2005/63c9376781325012a295a3f3c7436f5c to your computer and use it in GitHub Desktop.
chained grep with friendly syntax
#!/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