Como combinar coluna diferente no arquivo 1 e arquivo2 com awk?

0

Eu tenho os dois arquivos a seguir.

O primeiro arquivo é:

 3184 2014-07-28 04:15 global.Remote-Access 10.111.8.25 81.245.6.25 tcp
 3268

 3035 2014-07-28 04:16 global.Remote-Access 10.111.8.12 81.245.6.25 tcp
 3268

O segundo arquivo é:

 1 Jul 28 04:12 2014-07-28 id967254(group3)[attribute1 attribute2]
 Tunneling: User with IP 10.111.8.12 10 connected

 1 Jul 28 04:15 2014-07-28 id920767(group2)[attribute3 attribute4 ....
 attribute n] Tunneling: User with IP 10.111.8.25 connected

 1 Jul 28 04:16 2014-07-28 ID926072(group3)[attribute1 attribute2]
 Tunneling:User with IP 10.111.8.12 connected

Se o endereço IP de origem no arquivo 1 for igual ao arquivo 2, e se o tempo ( hh:mm ) e a data ( yyyy-mm-dd ) no arquivo 1 forem iguais a arquivo2, o terceiro arquivo será o seguinte :

 3184 04:15 2014-07-28 global.Remote-Access id920767(group2)[attribute3
 attribute4 .... attribute n] 10.111.8.25 81.245.6.25 tcp 3268

 3035 04:16 2014-07-28 global.Remote-Access ID926072(group3)[attribute1
 attribute2] 10.111.8.12 81.245.6.25 tcp 3268

Como posso perceber isso usando awk ?

    
por user79115 30.07.2014 / 09:26

2 respostas

1

Tente isto:

$ awk 'FNR==NR{a[$2$3$5];next} ($5$4$(NF-1)) in a' file1 file2 
1 Jul 28 04:15 2014-07-28 id920767(group2)[attribute3 attribute4 .... attribute n] Tunneling: User with IP 10.111.8.25 connected
1 Jul 28 04:16 2014-07-28 ID926072(group3)[attribute1 attribute2] Tunneling:User with IP 10.111.8.12 connected
    
por 30.07.2014 / 18:00
1
awk 'NR == FNR {t=($4 $5 $(NF-1));
  $1=$2=$3=$4=$5=X;
  $0=$0; $1=$1;
  sub(/].*$/, "]");
  a[t] = $0; next}
  ($3 $2 $5) in a {$4 = ($4 " " a[$3 $2 $5])}1' file2 file1
    
por 31.07.2014 / 05:52

Tags