
다음 두 파일이 있습니다.
첫 번째 파일은 다음과 같습니다.
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
두 번째 파일은 다음과 같습니다.
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
파일 1의 원본 IP 주소가 파일 2와 같고, 파일 1의 시간( hh:mm
)과 날짜( ) yyyy-mm-dd
가 파일 2와 같은 경우 세 번째 파일은 다음과 같습니다.
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
이를 달성하려면 어떻게 해야 합니까 awk
?
답변1
이 시도:
$ 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
답변2
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