使用命令行工具,我需要在关键字“检测到的协议”之后提取文本"HTTP“(或协议碰巧是什么):
部分文件内容:
Detected protocol:
HTTP 1254完整的文件内容:
nDPI Memory statistics:
nDPI Memory (once): 103.29 KB
Flow Memory (per flow): 1.91 KB
Actual Memory: 1.76 MB
Peak Memory: 1.76 MB
Traffic statistics:
Ethernet bytes: 1342 (includes ethernet CRC/IFC/trailer)
Discarded bytes: 0
IP packets: 10 of 10 packets total
IP bytes: 1102 (avg pkt size 110 bytes)
Detected protocols:
HTTP packets: 10 bytes: 1102 flows: 1
Protocol statistics:
Acceptable 1102 bytes发布于 2016-04-06 08:03:21
假设您只希望这种情况发生一次,您可以举例说:
awk 'matched {print $2; exit} /Detected protocol/ {matched=1}' file返回:
1254此检查是包含“检测到的协议”的一行。如果是,则设置一个标志,提示下一行中的打印。然后,它就退出了。
还可以将字段分隔符设置为HTTP。
awk -F"HTTP" 'f {print $2; exit} /Detected protocol/ {f=1}' file它为更新的输入文件返回以下内容:
packets: 10 bytes: 1102 flows: 1 发布于 2016-04-15 14:02:51
你也可以用
sed -n '/Dectected protocol/{n;p}' $filehttps://stackoverflow.com/questions/36444900
复制相似问题