Convert quoted string list to specific format

Tags: bash jq

I'm using jq to read some data from a JSON file.

after=`cat somefile.json | jq '.after[]'`

returns something like this:

"some value" "another value" "something else"

Basically a list of quoted strings. I now need to convert these strings into one string formatted like

"some value; another value; something else;"

I've tried a lot of combinations of for loops to try and get this working and nothing quite works.

Anyone know how this can be done? Cheers!


Thanks all! I actually decided to dig deeper into the jq docs to see if I could simply leverage it to do what I want.

after=`cat somefile.json | jq -c -r '.after[]   "; "'` | tr -d '\n'

This ended up working very well. Thanks for the sed version though! Always good to see another working solution.

This video can help you solving your question :)
By: admin