What's the easiest way to download and split the contents of
http://code.dlang.org/available
into a string array in Bash?
I then want to use this to provide completion for a bash commnd.
What's the easiest way to download and split the contents of
http://code.dlang.org/available
into a string array in Bash?
I then want to use this to provide completion for a bash commnd.
Of course, parsing deep JSON strings is a job for an dedicated JSON parser, but some simple cases (like this) is can be reduced to extracting quoted parts from an string and this can be done easily with grep such:
data=($(curl -s 'http://code.dlang.org/available' | grep -oP '[,\s"]+\K.*?(?=")'))
printf "%s\n" ${data[@]}
prints
zeal
arsd
cookbook
...
...
log4d
dvorm
dfl
Ps: It doesn't handles escaped \" but probably in this case it doesn't hurts.
jsonmodule. Why not use that to convert the content into something bash can easily process -- like a NUL-delimited list?