Reputation: 335
I'm trying to get a Value out of a information block.
I'm creating the following output:
RSSI: -21
RSSI: -12
RSSI: -13
RSSI: -13
RSSI: -16
RSSI: -13
with following command:
hcidump -a | egrep 'RSSI|bdaddr' | grep -A1 --no-group-separator 'bdaddr XX:XX:XX:XX:XX' | egrep 'RSSI'
But i would like to get only the Value at the end to be displayed. But I'm struggling with the right pattern, I found many hints online, but not one that will work, e.g.:
sed 's/RSSI: //'
Further I would like to know if there is a smoother way of my command on the top, because it seems with every | the output is getting slower, like it fills a buffer before it outputs the values.
PS: i wanna use this command in C with the system() function, is there an option to get the value to be stored in a C-variable?
Upvotes: 1
Views: 93
Reputation: 2292
No need for sed
, you can use cut
:
cut -d' ' -f2 myfile
This will output only the 2nd column, considering one whitespace as column delimiter.
Edit: to delete whitespaces at the beginning of each line in myfile, do this first:
sed -i 's/^ *//' myfile
Upvotes: 2
Reputation: 195029
Give this a try
hcidump -a |.. whatever...:XX:XX'|grep -Po 'RSSI:\s+\K.*'
or
hcidump -a |.. whatever...:XX:XX'|awk '/RSSI/{print $2}'
Upvotes: 2
Reputation: 3421
Or, if you have variable number of spaces in between, you can use following:
rev myfile | cut -d' ' -f1 | rev
Upvotes: 0