You do not need to pipe to grep
and then to awk
in the first line as awk
can do what's needed by itself. Also the way you have the first line written, it is missing the $(...)
around the commands.
In the second line you're missing the field separator in the awk
command, which in a .csv
file normally is a comma. So I added that to the awk
command.
Use the following two lines:
myBSSID="$(/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | awk '/BSSID/{print $2}')"
awk -F ',' -v theBSSID="$myBSSID" '$1 == theBSSID {print $2}' "$HOME/Desktop/APtable.csv"
I noticed the output of the airport
command didn't report the BSSID
correctly in that if left out some zeros.
If that's the case on your system and the .cvs
file has proper info, then try the following:
myBSSID="$(system_profiler SPAirPortDataType | awk '/BSSID/{print $2}')"
awk -F ',' -v theBSSID="$myBSSID" '$1 == theBSSID {print $2}' "$HOME/Desktop/APtable.csv"
Note that system_profiler SPAirPortDataType
isn't as fast as using airport
but if the output of airport
is dropping some of the zeros, then you'll need an alternative if the BSSID
's in the .cvs
file have all 12 characters, not counting the colons, which they should.
The following could be used to incorporate both methods in a bash
script so as to only use the second method if the length of myBSSID
is less then 17 characters, as 17 is the correct length.
#!/bin/bash
myBSSID="$(/S*/L*/P*/A*/V*/A/R*/airport -I | awk '/BSSID/{print $2}')"
l="${#myBSSID}"
if [[ $l -lt 17 ]]; then
myBSSID="$(system_profiler SPAirPortDataType | awk '/BSSID/{print $2}')"
fi
awk -F ',' -v theBSSID="$myBSSID" '$1 == theBSSID {print $2}' "$HOME/Desktop/APtable.csv"
pandas
module in python.awk: newline in string 94:b4:0f:ed:fd:b1 40... at source line 1