Created
September 23, 2013 00:32
-
-
Save KittyKatt/6665254 to your computer and use it in GitHub Desktop.
JSON parser in BASH using awk.
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
#!/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