2 parts to this, can't see where I'm going wrong

The 1st part works--get my BSSID through the airport command:

myBSSID="/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I | grep BSSID | awk '{print $2}'"

then (this is where I get EOF or syntax errors): pass that value to awk, which will search a file (APtable.csv) for that string, and give me the adjacent value to it:

awk -v theBSSID=$myBSSID '$1 == theBSSID {print $2}' '/Users/russell/Desktop/APtable.csv'
  • Depending on what you want to achieve in the end, you could also look into doing this in python; this answer provides a starting point, and you could easily store (access) the return values using e.g. the pandas module in python.
    – Asmus
    Jan 26, 2017 at 10:14
  • 1
    I've updated my answer, so you might want to review it. Jan 27, 2017 at 10:58
  • : ( Spoke too soon.
    – nuthindoin
    Jan 27, 2017 at 16:19
  • So, Murphy's Law, first BSSID I connect to has a leading 0, so the original script doesn't return anything. But running your addended script does get me something, but I'm not quite sure what: awk: newline in string 94:b4:0f:ed:fd:b1 40... at source line 1
    – nuthindoin
    Jan 27, 2017 at 16:29
  • It seems like awk finds what its looking for in column 1 of the file, but then doesn't print column 2 next to it.
    – nuthindoin
    Jan 27, 2017 at 17:01

1 Answer 1


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.


myBSSID="$(/S*/L*/P*/A*/V*/A/R*/airport -I | awk '/BSSID/{print $2}')"
if [[ $l -lt 17 ]]; then
    myBSSID="$(system_profiler SPAirPortDataType | awk '/BSSID/{print $2}')"
awk -F ',' -v theBSSID="$myBSSID" '$1 == theBSSID {print $2}' "$HOME/Desktop/APtable.csv"
  • 343-- I've noticed that too, (dropping of 0's)... weird. Can we be the first to notice this? But the important thing is, you got the code to work (together)! Thanks.
    – nuthindoin
    Jan 27, 2017 at 4:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .