Extract Bluetooth MAC Address: hcitool dev
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I have to extract from the command hcitool dev
only the MAC address of the bluetooth dongle.
Output of hcitool dev
is:
Devices:
hci0 xx:xx:xx:xx:xx:xx
I write this output to a file and try to get the info with awk
:
hcitool dev > /home/pi/mario/BT.txt
awk ' print $2 ' /home/pi/mario/BT.txt
The output also contains the first row which is an empty cell:
xx:xx:xx:xx:xx:xx
How can I put off the first cell?
text-processing hardware bluetooth mac-address usb-device
add a comment |Â
up vote
5
down vote
favorite
I have to extract from the command hcitool dev
only the MAC address of the bluetooth dongle.
Output of hcitool dev
is:
Devices:
hci0 xx:xx:xx:xx:xx:xx
I write this output to a file and try to get the info with awk
:
hcitool dev > /home/pi/mario/BT.txt
awk ' print $2 ' /home/pi/mario/BT.txt
The output also contains the first row which is an empty cell:
xx:xx:xx:xx:xx:xx
How can I put off the first cell?
text-processing hardware bluetooth mac-address usb-device
Can you paste a part of the contents in /home/pi/mario/BT.txt before applyingawk
?
â haxxor
Oct 31 '14 at 8:50
The content is equal to the output i posted before Devices: hci0 xx:xx:xx:xx:xx:xx
â mario
Oct 31 '14 at 10:26
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I have to extract from the command hcitool dev
only the MAC address of the bluetooth dongle.
Output of hcitool dev
is:
Devices:
hci0 xx:xx:xx:xx:xx:xx
I write this output to a file and try to get the info with awk
:
hcitool dev > /home/pi/mario/BT.txt
awk ' print $2 ' /home/pi/mario/BT.txt
The output also contains the first row which is an empty cell:
xx:xx:xx:xx:xx:xx
How can I put off the first cell?
text-processing hardware bluetooth mac-address usb-device
I have to extract from the command hcitool dev
only the MAC address of the bluetooth dongle.
Output of hcitool dev
is:
Devices:
hci0 xx:xx:xx:xx:xx:xx
I write this output to a file and try to get the info with awk
:
hcitool dev > /home/pi/mario/BT.txt
awk ' print $2 ' /home/pi/mario/BT.txt
The output also contains the first row which is an empty cell:
xx:xx:xx:xx:xx:xx
How can I put off the first cell?
text-processing hardware bluetooth mac-address usb-device
text-processing hardware bluetooth mac-address usb-device
edited Jan 20 '16 at 12:43
lgeorget
8,67622449
8,67622449
asked Oct 31 '14 at 8:46
mario
283
283
Can you paste a part of the contents in /home/pi/mario/BT.txt before applyingawk
?
â haxxor
Oct 31 '14 at 8:50
The content is equal to the output i posted before Devices: hci0 xx:xx:xx:xx:xx:xx
â mario
Oct 31 '14 at 10:26
add a comment |Â
Can you paste a part of the contents in /home/pi/mario/BT.txt before applyingawk
?
â haxxor
Oct 31 '14 at 8:50
The content is equal to the output i posted before Devices: hci0 xx:xx:xx:xx:xx:xx
â mario
Oct 31 '14 at 10:26
Can you paste a part of the contents in /home/pi/mario/BT.txt before applying
awk
?â haxxor
Oct 31 '14 at 8:50
Can you paste a part of the contents in /home/pi/mario/BT.txt before applying
awk
?â haxxor
Oct 31 '14 at 8:50
The content is equal to the output i posted before Devices: hci0 xx:xx:xx:xx:xx:xx
â mario
Oct 31 '14 at 10:26
The content is equal to the output i posted before Devices: hci0 xx:xx:xx:xx:xx:xx
â mario
Oct 31 '14 at 10:26
add a comment |Â
6 Answers
6
active
oldest
votes
up vote
3
down vote
accepted
For you purpose is quite enough grep
hcitool dev | grep -o "[[:xdigit:]:]11,17"
-o
outputs just finded patten
[[:xdigit:]:]
mean all hexadecimal digits plus :
char
11,17
the set of chars should be neither less then 11 no more 17 in length
1
The question seems asking help forawk
solution. But here you are usinggrep
!
â Pandya
Oct 31 '14 at 9:20
@Pandya for me it isn't look so.
â Costas
Oct 31 '14 at 9:24
Thanks @Costas, this is also cleaner without the need to use a file
â mario
Oct 31 '14 at 10:29
add a comment |Â
up vote
3
down vote
try
awk 'NR>1 print $2 ' /home/pi/mario/BT.txt
where
NR>1
means skip first row. (NR: Number of record)
In the case better use$2 != ""
because in the original first row there are first field ($1) =Devices:
â Costas
Oct 31 '14 at 9:01
@mario To be fair; I think this is the real answer to your question.
â tjt263
Jan 20 '16 at 12:20
add a comment |Â
up vote
1
down vote
cut
in:
hcitool dev | cut -sf3
out:
xx:xx:xx:xx:xx:xx
1
Why3
?â It looks to me like the desired output is the 2nd field.
â Scott
Oct 11 '17 at 16:36
add a comment |Â
up vote
1
down vote
hcitool dev | awk '$0=$2'
With awk
and many other languages, an assignment can be used as a conditional. The value assigned is then interpreted as a boolean value (integer zero, or an empty string, is "false").
In this case, the expression $0 = $2
will be "true" is there's anything in the second column. Regardless of whether there is or not, the contents of the line, $0
, will be replaced by this value.
In awk
, when a condition or pattern does not have a corresponding action block ( ...
) then the default action is to output the current line, as if the action had been print $0
or just print
.
This has the effect of printing the second white-space-delimited column in the input data, but only for the lines where there is actually something in the second column.
add a comment |Â
up vote
0
down vote
The below command displays complete details of Bluetooth like address, type, Tx bytes, Rx bytes, name, link policy, manufacturer
hciconfig -a
New contributor
add a comment |Â
up vote
-2
down vote
awk
in:
hcitool dev | awk '/hci0/ print $2'
out:
xx:xx:xx:xx:xx:xx
2
Brevity is acceptable, but fuller explanations are better.
â Kusalananda
Oct 11 '17 at 12:24
@tjt263 he had an observation and a suggestion that would help you make your answer better. That's known as being helpful, not a pest. Please be careful of your tone in future.
â terdonâ¦
Oct 12 '17 at 14:09
@terdon you're wrong.
â tjt263
Oct 12 '17 at 15:25
1
OK. Let's try this one more time. We expect answers here to be explanatory and clear. You have posted two answers, neither of which explains what they do or how they work. That is considered a bad answer here which is why you are getting downvoted. You can now choose to follow the advice of the helpful user who took the time to link you to the help center page which explains how to write good answers, or you can ignore and/or insult the people who try to help you. Your choice.
â terdonâ¦
Oct 12 '17 at 15:42
add a comment |Â
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
For you purpose is quite enough grep
hcitool dev | grep -o "[[:xdigit:]:]11,17"
-o
outputs just finded patten
[[:xdigit:]:]
mean all hexadecimal digits plus :
char
11,17
the set of chars should be neither less then 11 no more 17 in length
1
The question seems asking help forawk
solution. But here you are usinggrep
!
â Pandya
Oct 31 '14 at 9:20
@Pandya for me it isn't look so.
â Costas
Oct 31 '14 at 9:24
Thanks @Costas, this is also cleaner without the need to use a file
â mario
Oct 31 '14 at 10:29
add a comment |Â
up vote
3
down vote
accepted
For you purpose is quite enough grep
hcitool dev | grep -o "[[:xdigit:]:]11,17"
-o
outputs just finded patten
[[:xdigit:]:]
mean all hexadecimal digits plus :
char
11,17
the set of chars should be neither less then 11 no more 17 in length
1
The question seems asking help forawk
solution. But here you are usinggrep
!
â Pandya
Oct 31 '14 at 9:20
@Pandya for me it isn't look so.
â Costas
Oct 31 '14 at 9:24
Thanks @Costas, this is also cleaner without the need to use a file
â mario
Oct 31 '14 at 10:29
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
For you purpose is quite enough grep
hcitool dev | grep -o "[[:xdigit:]:]11,17"
-o
outputs just finded patten
[[:xdigit:]:]
mean all hexadecimal digits plus :
char
11,17
the set of chars should be neither less then 11 no more 17 in length
For you purpose is quite enough grep
hcitool dev | grep -o "[[:xdigit:]:]11,17"
-o
outputs just finded patten
[[:xdigit:]:]
mean all hexadecimal digits plus :
char
11,17
the set of chars should be neither less then 11 no more 17 in length
answered Oct 31 '14 at 9:12
Costas
12.5k1029
12.5k1029
1
The question seems asking help forawk
solution. But here you are usinggrep
!
â Pandya
Oct 31 '14 at 9:20
@Pandya for me it isn't look so.
â Costas
Oct 31 '14 at 9:24
Thanks @Costas, this is also cleaner without the need to use a file
â mario
Oct 31 '14 at 10:29
add a comment |Â
1
The question seems asking help forawk
solution. But here you are usinggrep
!
â Pandya
Oct 31 '14 at 9:20
@Pandya for me it isn't look so.
â Costas
Oct 31 '14 at 9:24
Thanks @Costas, this is also cleaner without the need to use a file
â mario
Oct 31 '14 at 10:29
1
1
The question seems asking help for
awk
solution. But here you are using grep
!â Pandya
Oct 31 '14 at 9:20
The question seems asking help for
awk
solution. But here you are using grep
!â Pandya
Oct 31 '14 at 9:20
@Pandya for me it isn't look so.
â Costas
Oct 31 '14 at 9:24
@Pandya for me it isn't look so.
â Costas
Oct 31 '14 at 9:24
Thanks @Costas, this is also cleaner without the need to use a file
â mario
Oct 31 '14 at 10:29
Thanks @Costas, this is also cleaner without the need to use a file
â mario
Oct 31 '14 at 10:29
add a comment |Â
up vote
3
down vote
try
awk 'NR>1 print $2 ' /home/pi/mario/BT.txt
where
NR>1
means skip first row. (NR: Number of record)
In the case better use$2 != ""
because in the original first row there are first field ($1) =Devices:
â Costas
Oct 31 '14 at 9:01
@mario To be fair; I think this is the real answer to your question.
â tjt263
Jan 20 '16 at 12:20
add a comment |Â
up vote
3
down vote
try
awk 'NR>1 print $2 ' /home/pi/mario/BT.txt
where
NR>1
means skip first row. (NR: Number of record)
In the case better use$2 != ""
because in the original first row there are first field ($1) =Devices:
â Costas
Oct 31 '14 at 9:01
@mario To be fair; I think this is the real answer to your question.
â tjt263
Jan 20 '16 at 12:20
add a comment |Â
up vote
3
down vote
up vote
3
down vote
try
awk 'NR>1 print $2 ' /home/pi/mario/BT.txt
where
NR>1
means skip first row. (NR: Number of record)
try
awk 'NR>1 print $2 ' /home/pi/mario/BT.txt
where
NR>1
means skip first row. (NR: Number of record)
edited Oct 31 '14 at 9:04
answered Oct 31 '14 at 8:57
Archemar
19.2k93468
19.2k93468
In the case better use$2 != ""
because in the original first row there are first field ($1) =Devices:
â Costas
Oct 31 '14 at 9:01
@mario To be fair; I think this is the real answer to your question.
â tjt263
Jan 20 '16 at 12:20
add a comment |Â
In the case better use$2 != ""
because in the original first row there are first field ($1) =Devices:
â Costas
Oct 31 '14 at 9:01
@mario To be fair; I think this is the real answer to your question.
â tjt263
Jan 20 '16 at 12:20
In the case better use
$2 != ""
because in the original first row there are first field ($1) = Devices:
â Costas
Oct 31 '14 at 9:01
In the case better use
$2 != ""
because in the original first row there are first field ($1) = Devices:
â Costas
Oct 31 '14 at 9:01
@mario To be fair; I think this is the real answer to your question.
â tjt263
Jan 20 '16 at 12:20
@mario To be fair; I think this is the real answer to your question.
â tjt263
Jan 20 '16 at 12:20
add a comment |Â
up vote
1
down vote
cut
in:
hcitool dev | cut -sf3
out:
xx:xx:xx:xx:xx:xx
1
Why3
?â It looks to me like the desired output is the 2nd field.
â Scott
Oct 11 '17 at 16:36
add a comment |Â
up vote
1
down vote
cut
in:
hcitool dev | cut -sf3
out:
xx:xx:xx:xx:xx:xx
1
Why3
?â It looks to me like the desired output is the 2nd field.
â Scott
Oct 11 '17 at 16:36
add a comment |Â
up vote
1
down vote
up vote
1
down vote
cut
in:
hcitool dev | cut -sf3
out:
xx:xx:xx:xx:xx:xx
cut
in:
hcitool dev | cut -sf3
out:
xx:xx:xx:xx:xx:xx
edited Oct 11 '17 at 11:22
answered Jan 17 '16 at 20:40
tjt263
4901420
4901420
1
Why3
?â It looks to me like the desired output is the 2nd field.
â Scott
Oct 11 '17 at 16:36
add a comment |Â
1
Why3
?â It looks to me like the desired output is the 2nd field.
â Scott
Oct 11 '17 at 16:36
1
1
Why
3
?â It looks to me like the desired output is the 2nd field.â Scott
Oct 11 '17 at 16:36
Why
3
?â It looks to me like the desired output is the 2nd field.â Scott
Oct 11 '17 at 16:36
add a comment |Â
up vote
1
down vote
hcitool dev | awk '$0=$2'
With awk
and many other languages, an assignment can be used as a conditional. The value assigned is then interpreted as a boolean value (integer zero, or an empty string, is "false").
In this case, the expression $0 = $2
will be "true" is there's anything in the second column. Regardless of whether there is or not, the contents of the line, $0
, will be replaced by this value.
In awk
, when a condition or pattern does not have a corresponding action block ( ...
) then the default action is to output the current line, as if the action had been print $0
or just print
.
This has the effect of printing the second white-space-delimited column in the input data, but only for the lines where there is actually something in the second column.
add a comment |Â
up vote
1
down vote
hcitool dev | awk '$0=$2'
With awk
and many other languages, an assignment can be used as a conditional. The value assigned is then interpreted as a boolean value (integer zero, or an empty string, is "false").
In this case, the expression $0 = $2
will be "true" is there's anything in the second column. Regardless of whether there is or not, the contents of the line, $0
, will be replaced by this value.
In awk
, when a condition or pattern does not have a corresponding action block ( ...
) then the default action is to output the current line, as if the action had been print $0
or just print
.
This has the effect of printing the second white-space-delimited column in the input data, but only for the lines where there is actually something in the second column.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
hcitool dev | awk '$0=$2'
With awk
and many other languages, an assignment can be used as a conditional. The value assigned is then interpreted as a boolean value (integer zero, or an empty string, is "false").
In this case, the expression $0 = $2
will be "true" is there's anything in the second column. Regardless of whether there is or not, the contents of the line, $0
, will be replaced by this value.
In awk
, when a condition or pattern does not have a corresponding action block ( ...
) then the default action is to output the current line, as if the action had been print $0
or just print
.
This has the effect of printing the second white-space-delimited column in the input data, but only for the lines where there is actually something in the second column.
hcitool dev | awk '$0=$2'
With awk
and many other languages, an assignment can be used as a conditional. The value assigned is then interpreted as a boolean value (integer zero, or an empty string, is "false").
In this case, the expression $0 = $2
will be "true" is there's anything in the second column. Regardless of whether there is or not, the contents of the line, $0
, will be replaced by this value.
In awk
, when a condition or pattern does not have a corresponding action block ( ...
) then the default action is to output the current line, as if the action had been print $0
or just print
.
This has the effect of printing the second white-space-delimited column in the input data, but only for the lines where there is actually something in the second column.
edited Oct 11 '17 at 16:55
answered Oct 11 '17 at 16:46
Kusalananda
109k14211334
109k14211334
add a comment |Â
add a comment |Â
up vote
0
down vote
The below command displays complete details of Bluetooth like address, type, Tx bytes, Rx bytes, name, link policy, manufacturer
hciconfig -a
New contributor
add a comment |Â
up vote
0
down vote
The below command displays complete details of Bluetooth like address, type, Tx bytes, Rx bytes, name, link policy, manufacturer
hciconfig -a
New contributor
add a comment |Â
up vote
0
down vote
up vote
0
down vote
The below command displays complete details of Bluetooth like address, type, Tx bytes, Rx bytes, name, link policy, manufacturer
hciconfig -a
New contributor
The below command displays complete details of Bluetooth like address, type, Tx bytes, Rx bytes, name, link policy, manufacturer
hciconfig -a
New contributor
New contributor
answered 9 mins ago
Sai
1
1
New contributor
New contributor
add a comment |Â
add a comment |Â
up vote
-2
down vote
awk
in:
hcitool dev | awk '/hci0/ print $2'
out:
xx:xx:xx:xx:xx:xx
2
Brevity is acceptable, but fuller explanations are better.
â Kusalananda
Oct 11 '17 at 12:24
@tjt263 he had an observation and a suggestion that would help you make your answer better. That's known as being helpful, not a pest. Please be careful of your tone in future.
â terdonâ¦
Oct 12 '17 at 14:09
@terdon you're wrong.
â tjt263
Oct 12 '17 at 15:25
1
OK. Let's try this one more time. We expect answers here to be explanatory and clear. You have posted two answers, neither of which explains what they do or how they work. That is considered a bad answer here which is why you are getting downvoted. You can now choose to follow the advice of the helpful user who took the time to link you to the help center page which explains how to write good answers, or you can ignore and/or insult the people who try to help you. Your choice.
â terdonâ¦
Oct 12 '17 at 15:42
add a comment |Â
up vote
-2
down vote
awk
in:
hcitool dev | awk '/hci0/ print $2'
out:
xx:xx:xx:xx:xx:xx
2
Brevity is acceptable, but fuller explanations are better.
â Kusalananda
Oct 11 '17 at 12:24
@tjt263 he had an observation and a suggestion that would help you make your answer better. That's known as being helpful, not a pest. Please be careful of your tone in future.
â terdonâ¦
Oct 12 '17 at 14:09
@terdon you're wrong.
â tjt263
Oct 12 '17 at 15:25
1
OK. Let's try this one more time. We expect answers here to be explanatory and clear. You have posted two answers, neither of which explains what they do or how they work. That is considered a bad answer here which is why you are getting downvoted. You can now choose to follow the advice of the helpful user who took the time to link you to the help center page which explains how to write good answers, or you can ignore and/or insult the people who try to help you. Your choice.
â terdonâ¦
Oct 12 '17 at 15:42
add a comment |Â
up vote
-2
down vote
up vote
-2
down vote
awk
in:
hcitool dev | awk '/hci0/ print $2'
out:
xx:xx:xx:xx:xx:xx
awk
in:
hcitool dev | awk '/hci0/ print $2'
out:
xx:xx:xx:xx:xx:xx
answered Oct 11 '17 at 11:21
tjt263
4901420
4901420
2
Brevity is acceptable, but fuller explanations are better.
â Kusalananda
Oct 11 '17 at 12:24
@tjt263 he had an observation and a suggestion that would help you make your answer better. That's known as being helpful, not a pest. Please be careful of your tone in future.
â terdonâ¦
Oct 12 '17 at 14:09
@terdon you're wrong.
â tjt263
Oct 12 '17 at 15:25
1
OK. Let's try this one more time. We expect answers here to be explanatory and clear. You have posted two answers, neither of which explains what they do or how they work. That is considered a bad answer here which is why you are getting downvoted. You can now choose to follow the advice of the helpful user who took the time to link you to the help center page which explains how to write good answers, or you can ignore and/or insult the people who try to help you. Your choice.
â terdonâ¦
Oct 12 '17 at 15:42
add a comment |Â
2
Brevity is acceptable, but fuller explanations are better.
â Kusalananda
Oct 11 '17 at 12:24
@tjt263 he had an observation and a suggestion that would help you make your answer better. That's known as being helpful, not a pest. Please be careful of your tone in future.
â terdonâ¦
Oct 12 '17 at 14:09
@terdon you're wrong.
â tjt263
Oct 12 '17 at 15:25
1
OK. Let's try this one more time. We expect answers here to be explanatory and clear. You have posted two answers, neither of which explains what they do or how they work. That is considered a bad answer here which is why you are getting downvoted. You can now choose to follow the advice of the helpful user who took the time to link you to the help center page which explains how to write good answers, or you can ignore and/or insult the people who try to help you. Your choice.
â terdonâ¦
Oct 12 '17 at 15:42
2
2
Brevity is acceptable, but fuller explanations are better.
â Kusalananda
Oct 11 '17 at 12:24
Brevity is acceptable, but fuller explanations are better.
â Kusalananda
Oct 11 '17 at 12:24
@tjt263 he had an observation and a suggestion that would help you make your answer better. That's known as being helpful, not a pest. Please be careful of your tone in future.
â terdonâ¦
Oct 12 '17 at 14:09
@tjt263 he had an observation and a suggestion that would help you make your answer better. That's known as being helpful, not a pest. Please be careful of your tone in future.
â terdonâ¦
Oct 12 '17 at 14:09
@terdon you're wrong.
â tjt263
Oct 12 '17 at 15:25
@terdon you're wrong.
â tjt263
Oct 12 '17 at 15:25
1
1
OK. Let's try this one more time. We expect answers here to be explanatory and clear. You have posted two answers, neither of which explains what they do or how they work. That is considered a bad answer here which is why you are getting downvoted. You can now choose to follow the advice of the helpful user who took the time to link you to the help center page which explains how to write good answers, or you can ignore and/or insult the people who try to help you. Your choice.
â terdonâ¦
Oct 12 '17 at 15:42
OK. Let's try this one more time. We expect answers here to be explanatory and clear. You have posted two answers, neither of which explains what they do or how they work. That is considered a bad answer here which is why you are getting downvoted. You can now choose to follow the advice of the helpful user who took the time to link you to the help center page which explains how to write good answers, or you can ignore and/or insult the people who try to help you. Your choice.
â terdonâ¦
Oct 12 '17 at 15:42
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f165192%2fextract-bluetooth-mac-address-hcitool-dev%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Can you paste a part of the contents in /home/pi/mario/BT.txt before applying
awk
?â haxxor
Oct 31 '14 at 8:50
The content is equal to the output i posted before Devices: hci0 xx:xx:xx:xx:xx:xx
â mario
Oct 31 '14 at 10:26