extrair nomes de domínio (nomes de host) de um arquivo de texto

1

Eu queria extrair o nome de domínio (nome do host) com o Tempo limite de conexão esgotado com 5 atrasos.

arquivo de entrada

Mar 19 21:44:00 ip-172-2-0-53 sendmail[30686]: v2K4g0Dm030684: to=<[email protected]>, delay=00:02:12, xdelay=00:02:00, mailer=esmtp, pri=120847, relay=webmail.jehdns.com. [192.168.1.1], dsn=4.0.0, stat=Deferred: Connection timed out with webmail.jehdns.com.
Mar 19 20:35:00 ip-172-2-0-54 sendmail[30683]: v2K4g0Dm030684: to=<[email protected]>, delay=00:02:00, xdelay=00:02:00, mailer=esmtp, pri=120847, relay=webmail.jehdns.com. [192.168.1.1], dsn=4.0.0, stat=Deferred: Connection timed out with webmail.karna.com.
Mar 21 23:15:20 ip-172-2-0-53 sendmail[7742]: v2M6FKZm007741: to=<[email protected]>, ctladdr=<[email protected]> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31116, dsn=2.0.0, stat=Sent

Resultado esperado:

Mar 19 21 delay=00:02:12 - webmail.jehdns.com.
Mar 20 13 delay=00:02:00 - webmail.karna.com.
    
por Mahesh Phate 07.04.2017 / 14:06

2 respostas

1
sed -n '/timed out/{s/^\([^:]*\):.*xdelay=\([^,]*\),.*with \(.*\)$/ delay= - /;p;}' 
    
por 07.04.2017 / 14:19
0
perl -F: -lane '
   ($i) = grep { $F[$_] =~ /delay=/ } 0 .. $#F;
   $d = join ":", join($\, @F[$i..$i+2]) =~ /\hdelay=\K\d+|\n\K\d+/g;
   print "$d:$F[0]", " delay=$d", " - ", /\S+$/g if $F[-1] =~ /timed out/;
' input_file |
 sort -t: -nr -k1,1 -k2,2 -k3,3 | cut -d: -f4-

Saída

Mar 19 21 delay=00:02:12 - webmail.jehdns.com.
Mar 19 20 delay=00:02:00 - webmail.karna.com.
    
por 07.04.2017 / 17:07