Sujet : Re: Useless Use Of Regexes
De : anssi.saari (at) *nospam* usenet.mail.kapsi.fi (Anssi Saari)
Groupes : comp.os.linux.miscDate : 25. Mar 2025, 10:09:52
Autres entêtes
Organisation : An impatient and LOUD arachnid
Message-ID : <sm0o6xpqxwf.fsf@lakka.kapsi.fi>
References : 1 2 3
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Lawrence D'Oliveiro <
ldo@nz.invalid> writes:
Don’t forget the option of JSON-format output, for even easier processing
in scripts than messing around with regexes.
Kinda yes, but for a script I'd really like to just get the data
directly in an associative array that I can use as is. Instead of
messing around with jq. I just took a look around in Stack Exchange but
meh. One simplish bash example was this:
typeset -A myarray
while IFS== read -r key value; do
myarray["$key"]="$value"
done < <(jq -r '.SITE_DATA | to_entries | .[] | .key + "=" + .value ' file.json)
But that still pukes if the data happens to have a numeric value and in
ip route output at least the metric value is numeric. So apparently it
needs to become .key + "=" + (.value|tostring) to handle that.