Deutsch English Français Italiano |
<sm0o6xpqxwf.fsf@lakka.kapsi.fi> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Anssi Saari <anssi.saari@usenet.mail.kapsi.fi> Newsgroups: comp.os.linux.misc Subject: Re: Useless Use Of Regexes Date: Tue, 25 Mar 2025 11:09:52 +0200 Organization: An impatient and LOUD arachnid Lines: 19 Message-ID: <sm0o6xpqxwf.fsf@lakka.kapsi.fi> References: <vrsfkv$1md7d$1@dont-email.me> <vrsjva$1oouq$1@dont-email.me> <vrso4m$1toah$3@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 25 Mar 2025 10:09:56 +0100 (CET) Injection-Info: dont-email.me; posting-host="c49268631d370494f95e4d97760fe48c"; logging-data="3150737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fetqmkgkRqqc4wiy7SXiX" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cancel-Lock: sha1:3WtAOeNV9PYepjXBP5DEXRm+Pw8= sha1:hcKgmJ6b6D7wV6nCcEaiIdfDk0A= Bytes: 1909 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.