Last active
May 2, 2022 04:59
-
-
Save cmdruid/47cd68f98f72b176b1eb6b030325a20d to your computer and use it in GitHub Desktop.
Simple script that extracts the value for a given key within a JSON output.
This file contains hidden or 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
#!/bin/sh | |
## Takes an input pipe of JSON, and outputs the value for a given key. | |
set -e | |
usage() { | |
printf " | |
Takes an input pipe of JSON, and outputs the value for a given key. \n | |
Usage: some_JSON_output | jgrep key \n | |
" | |
} | |
## If argument empty or help, display help message. | |
if [ -z "$1" ] || [ "$1" = "--help" ]; then usage && exit 0; fi | |
## Grep the key from the JSON input, then sanitize. | |
grep $1 | awk '{print $2}' | tr -d ',"' < /dev/stdin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment