得到的grep匹配后的下一个字 [英] get the next word after grep matching
问题描述
我使用这个命令来获取连接到接入点客户端的信号平均功率:
IW开发为wlan0站转储| grep的-E'站|信号平均':
我得到了以下信息:
站my_MAC_Address(上为wlan0)
信号平均值: -46 dBm的
在大胆的是我使用grep匹配,我只是只想要匹配后得到了这个词,即MAC地址和数字-46。
我一直在玩的awk但没有成功。
希望你能帮帮我!
IW开发为wlan0站转储| grep的-Po(小于=站\\ S |信号平均值:\\ S)[^ \\ S] *
输出示例:
00:11:22:33:44:55
-40
更新:
感谢您的投票这个答案了。现在我知道另一种解决方案:
IW开发为wlan0站转储| grep的-Po'(站\\ s |信号平均值:\\ S)\\ K表[^ \\ S] *
这实际上是上述解决方案的简写。 \\氏/ code>基本意思是忘记了它的次数之前一切。
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':
I got the following info:
Station "my_MAC_Address" (on wlan0)
signal avg: -46 dBm
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 '(?<=Station\s|signal avg:\s)[^\s]*'
This regexp uses a so-called lookbehind
syntax. You can read about it here
Example output:
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 '(Station\s|signal avg:\s)\K[^\s]*'
Which is actually a shorthand for the solution above. \K
basically means "forget everything before its occurance".
这篇关于得到的grep匹配后的下一个字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!