Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • Ah, nice! I was hoping someone could come up with something better than that monstrosity I posted. You could just pass the output through perl -pe 's/([a-zA-Z]+)/\u$1/g; to get the capitalization as the OP had it. Commented Sep 10, 2024 at 19:49
  • Thank you, this is elegant. Since I asked to avoid any additional tools, I've accepted @StéphaneChazelas suggestion as answer below. However, I think I will be using this one regardless :-) On a side note, I thought it would be good to add the interface to the output, which can be achieved by using ip -j a | jq 'foreach .[] as $item (0; . +1; $item.addr_info [] as $a | {ifname: $item.ifname} * $a)' | mlr --j2p unsparsify Commented Sep 11, 2024 at 7:29
  • 1
    @hanjo Don't do explicit counting loop when you don't need to: .[] | .ifname as $ifname | .addr_info | map(.ifname=$ifname) | flatten. If you want the ifname field first in the result, then reorder with mlr: mlr --j2p unsparsify then reorder -f ifname Commented Sep 11, 2024 at 7:40
  • @Kusalananda good to know, thanks. Still learning here. On my test machine (Raspberry Pi Model B Rev 2) avoiding the foreach saved 3ms, so I guess the performance advantage is neglectable for this specific use case, but I get the idea. Don't use loops if not absolutely required. Commented Sep 11, 2024 at 7:49
  • @hanjo Well, :-), I hope the millisecond performance gain makes up for the time spent working on the script... Commented Sep 11, 2024 at 7:52