I’m working on a short bash script to grab a JSON element from a curl response.
curl -H "api_key:[API_PASSWORD]" http://api.wordnik.com/v4/word.json/button/pronunciations?sourceDictionary=macmillan&typeFormat=IPA&useCanonical=false
returns:
[{"id":0,"seq":0,"raw":"ˈbʌt(ə)n","rawType":"IPA"},{"id":0,"seq":0,"raw":"ˈbʌt(ə)n","rawType":"IPA"}]
I’m trying to extract the “ˈbʌt(ə)n” element.
Though I’m unfamiliar with regex, I think I should be using a substitution with this string:
/.*"(.*)",/
I’m trying to run the following command, but it doesn’t seem to work:
curl -H "api_key:[API_KEY]" http://api.wordnik.com/v4/word.json/button/pronunciations?sourceDictionary=macmillan&typeFormat=IPA&useCanonical=false | sed /.*"(.*)",\1/
I’m sure there are a few things I’m doing wrong, and after a few hours of searching and reading up on regex and bash I’m out of options.
I don’t need to be using sed, I am simply looking for a quick way of doing this in a bash command line so that I can implement it in a TextExpander script on the mac.
Use
STRING : REGEXPto extract the value from the json string:See
man expr: