Skip to content

Instantly share code, notes, and snippets.

@KittyKatt
Created September 23, 2013 00:32
Show Gist options
  • Save KittyKatt/6665254 to your computer and use it in GitHub Desktop.
Save KittyKatt/6665254 to your computer and use it in GitHub Desktop.
JSON parser in BASH using awk.
#!/usr/bin/env bash
function json_awk() {
_mykey="$1"
_mysearch="$2"
echo "$_mysearch" 2>/dev/null | awk -F"\",\"" -v k="$_mykey" '{
gsub(/{|}/,"")
for(i=1;i<=NF;i++){
if ( $i ~ k ){
print $i
}
}
}' &2>/dev/null
}
echo "$(json_awk "$@")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment