diff options
author | makefu <root@pigstarter.de> | 2014-03-14 12:17:47 +0100 |
---|---|---|
committer | makefu <root@pigstarter.de> | 2014-03-14 12:17:47 +0100 |
commit | a5c8fb018527b8642e6be01a9e2fc1af7cb80cb7 (patch) | |
tree | 70f89440f7f6e505adacc2a2775e3bc5e3447db2 /services/lib | |
parent | b25891641316dcaf5c469a22b96393e6e55fc5fe (diff) | |
parent | f92547a54d899216a4cd849ee515726824467765 (diff) |
Merge branch 'master' of https://github.com/krebscode/painload
Diffstat (limited to 'services/lib')
-rwxr-xr-x | services/lib/filter | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/services/lib/filter b/services/lib/filter new file mode 100755 index 00000000..f69a5b0d --- /dev/null +++ b/services/lib/filter @@ -0,0 +1,54 @@ +#! /bin/sh +# +# usage: +# export PATH="//services/lib:$PATH" +# cd services +# ls | filter owner == $LOGNAME | filter hasnt mail +# +set -euf + +main() { + case $# in + 2) op1 "$@";; + 3) op2 "$@";; + *) echo 'You are made of stupid!' >&2; exit 23;; + esac +} + +# op1 OP SCHEMA +op1() { + case "$1" in + has) + xargs grep -H "^$2:" \ + | cut -d: -f1 + ;; + hasnt) + a=$(mktemp) + b=$(mktemp) + trap "rm $a $b; trap - EXIT INT QUIT" EXIT INT QUIT + cat > $a + cat $a | xargs grep -H "^$2:" | cut -d: -f1 > $b + diff -u $b $a | sed -n '/^++/d;s/^+\(.*\)/\1/p' | grep . + esac +} + +# op2 SCHEMA OP RHS +op2() { + case "$2" in + ==|is) + xargs grep -H "^$1:$3$" \ + | cut -d: -f1 + ;; + !=|isnt) + xargs grep -H "^$1:" \ + | grep -v ":$1:$3" \ + | cut -d: -f1 + ;; + contains) + xargs grep -H "^$1:.*$3.*$" \ + | cut -d: -f1 + ;; + esac +} + +main "$@" |