【发布时间】:2013-10-28 01:57:17
【问题描述】:
我正在处理一组需要特定字段作为输出的数据:
数据如下:
/home/oracle/db.log.gz:2013-1-19T00:00:25 <user.info> 1 2013-1-19T00:00:53.911 host_name RT_FLOW [junos@26.1.1.1.2.4 source-address="10.1.2.0" source-port="616" destination-address="100.1.1.2" destination-port="23" service-name="junos-telnet" nat-source-address="20x.2x.1.2" nat-source-port="3546" nat-destination-address="9x.12x.3.0"]
从上面我需要三样东西:
(I) - 2013-1-19T00:00:53.911 which is $4
(II)- source-address="10.1.2.0" which is $8 of which I need only 10.1.2.0
(III) - destination-address="100.1.1.2" which $10 of which I need only 100.1.1.2
我不能像 -> awk '{ print $4 \t $8 \t $10 }' 这样使用简单的 awk,因为日志文件中的“device_name”后面有一些字段并不总是出现在所有日志行中,所以我必须使用分隔符,例如
awk -F 'source-address=' '{print $2}' | awk '{print $1} -> 这给出了源地址IP,这是(II)要求
我不确定如何使用 awk 搜索 I、II 和 III 进行组合。
有人可以帮忙吗?
【问题讨论】:
标签: awk