Is there a way to remove the duplicate and empty SSIDs?
output of nmcli -f SSID dev wifi
SSID
--
V-ODT
--
V-ODT
--
V-ODT
--
RTU240-156B
fortinet
desired output
SSID
V-ODT
RTU240-156B
fortinet
output of nmcli dev wifi list --rescan yes
IN-USE BSSID SSID MODE CHAN RATE SIGNAL BARS SECURITY
03:EC:DA:79:C7:1F -- Infra 11 195 Mbit/s 100 ▂▄▆█ WPA2
* 03:EC:DA:79:C7:1E V-ODT Infra 40 540 Mbit/s 94 ▂▄▆█ WPA2
07:EC:DA:79:C7:1E -- Infra 40 540 Mbit/s 94 ▂▄▆█ WPA2
61:22:33:18:20:BE V-ODT Infra 1 260 Mbit/s 84 ▂▄▆█ WPA2
63:22:33:18:20:BE -- Infra 1 260 Mbit/s 79 ▂▄▆_ WPA2
63:22:33:18:20:BF V-ODT Infra 36 540 Mbit/s 59 ▂▄▆_ WPA2
63:22:33:28:20:BF -- Infra 36 540 Mbit/s 59 ▂▄▆_ WPA2
01:1E:42:3C:16:6B RUT240_156B Infra 8 65 Mbit/s 57 ▂▄▆_ WPA2
05:D5:90:E7:5A:60 fortinet Infra 1 195 Mbit/s 30 ▂___ WPA2
You can pipe the output through sort
and uniq
. uniq
filters duplicates, but requires the input to be sorted.
To filter the --
, use grep
. However, Unix commands use hyphens to indicate options. When they should treat something starting with a hyphen as non-option arguments, the convention is to add --
to indicate the end of the options. So you need to add --
twice to grep
here, once to signal the end of the options, and once for what you actually want to filter.
nmcli -f SSID dev wifi | sort | uniq | grep -v -- --