获取grep匹配后的下一个单词 [英] get the next word after grep matching
问题描述
我正在使用此命令来检索连接到接入点的客户端的信号平均功率:
I'm using this command to retrieve the signal average power of a client connected to an Access Point:
iw dev wlan0 station dump | grep -E 'Station|signal avg':
我得到以下信息:
站my_MAC_Address"(在 wlan0 上)
Station "my_MAC_Address" (on wlan0)
信号平均值: -46 dBm
粗体是我与 grep 匹配的内容,我只想得到匹配后的单词,即 MAC 地址和数字 -46.我一直在玩 awk 但没有成功.希望你能帮助我!
In bold is what I matches with grep and I just only want to get the word after that matching, i.e the MAC address and the number -46. I've been playing with awk but without success. hope you can help me!
推荐答案
iw dev wlan0 station dump | grep -Po '(?<=Stations|signal avg:s)[^s]*'
这个正则表达式使用所谓的lookbehind
语法.你可以在这里
This regexp uses a so-called lookbehind
syntax. You can read about it here
示例输出:
00:11:22:33:44:55
-40
更新:
感谢您对这个答案投票.现在我知道另一个解决方案:
Update:
Thanks for voting this answer up. Now I know another solution:
iw dev wlan0 station dump | grep -Po '(Stations|signal avg:s)K[^s]*'
这实际上是上述解决方案的简写.K
基本上意味着在它发生之前忘记一切".
Which is actually a shorthand for the solution above. K
basically means "forget everything before its occurance".
这篇关于获取grep匹配后的下一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!