then you get results in a multi-line paragraph that look something like this:
networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Wi-Fi
Display Ethernet
Bluetooth DUN
Thunderbolt Ethernet
Display FireWire
Bluetooth PAN
Thunderbolt Bridge
I need to capture each of the network services reported and add that to either a variable or an array.
Problem #1 is that first sentence. I don't wish to capture it but DO wish to capture everything else.
Problem #2 is that cut -d, cut -c and awk '{ print $x }' are all failing because they only appear to scan results form the first line, not the others that follow.
Not sure if this is a job for sed or perl, but not super good with either of those commands and their syntax. Open to yer thoughts, oh wise ones.
and it's returning a lot of zeros. Your example only returns numbers as well:
1 10
2 1
3 2
4 2
5 1
6 1
7 2
I'm looking for the alphanumeric results but at least we now know the bnumber of spaces as delimiters....
@Aia - Your code DID return alphanumeric, but omitted the line items with no spaces in their name like "Wi-Fi" or "Ethernet".
---------- Post updated at 01:19 PM ---------- Previous update was at 01:06 PM ----------
Houston: we found a solution.
networksetup -listallnetworkservices | awk 'NR>1'
Wi-Fi
Display Ethernet
Bluetooth DUN
Thunderbolt Ethernet
Display FireWire
Bluetooth PAN
Thunderbolt Bridge
Sorry I meant NR>1 and somehow I interpolated an F instead of a R.
NF means Number of Fields
NR means Number of Records (normally lines)
Glad you found the same solution. I corrected it in the previous post.
Appreciate the follow up. The issue now is a bit more devious: setting an array with these values doesn't know how to break up the resulting text! Perhaps another problem for another thread, perhaps not.
Here's the original code:
networksetup -listallnetworkservices | awk 'NR>1'
Wi-Fi
Display Ethernet
Bluetooth DUN
Thunderbolt Ethernet
Display FireWire
Bluetooth PAN
Thunderbolt Bridge
Now, if I set a variable and then print those results to that variable, I get a series of words that aren't parsed by LINE. First, the variable:
echo $services
Wi-Fi Display Ethernet Bluetooth DUN Thunderbolt Ethernet Display FireWire Bluetooth PAN Thunderbolt Bridge
All those spaces essentially defeat the initial reason I needed this list in the first place! I need individual entries for each line, added into the array: Wi-Fi, Display Ethernet, Bluetooth DUN, Thunderbolt Ethernet, etc.