I'm trying to process output from nmcli command (colon separated values), but failing to handle / ignore escaped colons in MAC or BSSID. I've tried awk, jq, sed, regex but just not getting it...
piped command:
nmcli -f SSID,BSSID,CHAN,FREQ,SIGNAL,SECURITY -t dev wifi
example output:
WiFi:00\:0A\:97\:6F\:7B\:AC:165:5660 MHz:15:
If I move BSSID to the end of the line / field's list (and then just cut the last field) it'll work, but now it's a matter a pride. Please help!
I did find this existing stackoverflow thread, which really went about it nicely, but I'm ultimatly running into the same problem of how to ignore the escaped colon in the MAC!@%$ address: parse colon separated value pairs
Most recent (readable) attempt:
printf '%s' "$(nmcli -f SSID,BSSID,CHAN,FREQ,SIGNAL,SECURITY -t dev wifi)" | jq -sR 'split("\n") | map(split(":")) | map({"SSID": .[0], "BSSID": .[1], "CHAN": .[2], "RATE": .[3], "FREQ": .[4], "SIGNAL": .[5], "SECURITY": .[6]})'
and problem output:
...
{
"SSID": "WiFi",
"BSSID": "00\\",
"CHAN": "0A\\",
"RATE": "97\\",
"FREQ": "6F\\",
"SIGNAL": "7B\\",
"SECURITY": "AC"
},
...
Would also need JQ to leave colons in place and not escape as shown above, if at all possible, ... please don't just say python...