Getting RSSI Vaule from shell

'm trying to get the TxPower(RSSI) Value of an iBeacon (BEACONinside, ModelNo. B0001-A) and I'm struggling to get this value into a Python-, C- or Shellscript. I looked through many Tutorials and Stackoverflow Questions, but (since BLE is quiet new) I'm not able to find anything to start with.

I'm able to get the data on the commandline with

sudo hcidump -a | egrep 'RSSI|bdaddr'

But I'm getting also the RSSI value of an BLE-device with status 'random', and no further information for it. My knowledge of regular expressions is pretty limited and so i don't know how i can get only the Data from the device I want.

And as said at the top i would like to get this information into a script so I can use it for further actions.

Here is the output of the hcidump:

  bdaddr 20:C3:8F: D1:0E:B1 (Public)
  RSSI: -28
  bdaddr 20:C3:8F: D1:0E:B1 (Public)
  RSSI: -28
  bdaddr 20:C3:8F: D1:0E:B1 (Public)
  RSSI: -31
  bdaddr 20:C3:8F: D1:0E:B1 (Public)
  RSSI: -32
  bdaddr 20:C3:8F: D1:0E:B1 (Public)
  RSSI: -28
  bdaddr 20:C3:8F: D1:0E:B1 (Public)
  RSSI: -28
  bdaddr DD:45:C9: 26:61:51 (Random)
  RSSI: -57
  bdaddr DD:45:C9: 26:61:51 (Random)
  RSSI: -60
  bdaddr 20:C3:8F: D1:0E:B1 (Public)
  RSSI: -29

I know the bdaddr of the devices i want to scan for. so I would like to get only the RSSI for these devices.

I already thought of awk, sed and regex, but my knowledge of these thinks are very limited. could someone give me a hint. Or tell me that I'm completly on the wrong road and should it do it differently and how?

thanks and best regards
Adrian

Try something like:

sudo hcidump -a |awk -v addr="20:C3:8F: D1:0E:B1" '/bdaddr/ && $0~addr {p=$0} /RSSI/{print p; print}'

I do not know if that space in the middle of the bdaddress is supposed to be there, if not leave it out