Last active
May 24, 2018 16:53
-
-
Save tst2005/1ff0040e33621e90734b9c1fc735a23f to your computer and use it in GitHub Desktop.
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
getrawdata() { | |
printf '[ | |
{ "id": "bar", "info": "A babab" }, | |
{ "id": "buz", "info": "B ububu" }, | |
{ "id": "foo", "info": "A fofof" } | |
]'; | |
} | |
rawdata_to_db() { | |
jq '{db: .}'; | |
} | |
keepresult() { | |
jq '(.result|map({key:., value:true})|from_entries) as $want | .db |= map(select($want[.id]))|del(.result)' | |
} | |
search() { | |
local arg="$1" | |
jq ' | |
def grep($arg): test($arg); | |
def myfilter: '"$arg"'; | |
.+{ result: [.db[]|select( myfilter ).id] } | |
' | |
} | |
getdb() { | |
getrawdata | rawdata_to_db | |
} | |
dbquery() { | |
search "$1" | keepresult | |
} | |
sample() { | |
getdb | | |
dbquery '.info|grep("^A")' | | |
dbquery '(.info|grep("^Z")|not)' | | |
dbquery '.id!="zz"' | |
} | |
sample |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment