LVL*_*ron 5 sed awk syslog text
Example line from syslog file:
Aug 1 10:25:50 10.10.10.1 id=firewall sn=XXXX time="2012-08-01 14:35:18 UTC" fw=x.x.x.x pri=6 c=1024 m=537 msg="Connection Closed" f=11 n=195273698 src=x.x.x.x:60246:X3: dst=x.x.x.x:443:X6:host.domain.com proto=tcp/https sent=181793 rcvd=649678
Run Code Online (Sandbox Code Playgroud)
我想做一个
$ tail -f /var/log/log.log | SOMETHING
Run Code Online (Sandbox Code Playgroud)
那会回来
"src=x.x.x.x dst=x.x.x.x"
Run Code Online (Sandbox Code Playgroud)
简单地说,我希望能够从文本中提取特定字段。我不想根据字段编号(行中的位置)选择这些字段,因为随着系统生成此文件,事物的顺序可能会略有变化,因此它不起作用。
对建议持开放态度,但更喜欢单线。
tail -f log | perl -e 'while (<>) { print "src=$1 dst=$2\n" if $_ =~ /src=([^\s]+) dst=([^\s]+)/; }'