[英]How to use grep to get only part of a line
when i try to send command ifconfig im getting this当我尝试发送命令 ifconfig 我得到这个
ath0 IEEE 802.11ng ESSID:"test" Nickname:""
Mode:Master Frequency:2.412 GHz Access Point: 00:00:00:00:00:00
Bit Rate:0 kb/s Tx-Power=-4 dBm Sensitivity=16/16
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=0/94 Signal level=-96 dBm Noise level=-96 dBm
Rx invalid nwid:475654423 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
how to get from this only part of lines for example例如,如何从这部分行中获取
ESSID:""test
Frequency:2.412 GHz
Given your actual paste (and disregarding the malformed sample output):鉴于您的实际粘贴(并忽略格式错误的样本输出):
$ cat ifconf
ath0 IEEE 802.11ng ESSID:"test" Nickname:""
Mode:Master Frequency:2.412 GHz Access Point: 00:00:00:00:00:00
Bit Rate:0 kb/s Tx-Power=-4 dBm Sensitivity=16/16
Retry:off RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality=0/94 Signal level=-96 dBm Noise level=-96 dBm
Rx invalid nwid:475654423 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0
$ grep -oE 'ESSID:"[^"]+"|Frequency:[^ ]+' ifconf
ESSID:"test"
Frequency:2.412
it's really just an extended RegEx, and grep's -o
flag to ONLY output the exact match, rather than the matching line.它实际上只是一个扩展的 RegEx,并且 grep 的
-o
标志仅输出精确匹配,而不是匹配行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.