0

I have the following two files.

The first file is :

 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 

The second file is:

 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 

If the source IP address in the file 1 is equal to file 2 , and if the time (hh:mm) and date (yyyy-mm-dd) in the file 1 are equal to file2, the third file will be as follows:

 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 

How can I realise this using awk?

5
  • file1 in your input does not contain any attribute? Commented Jul 30, 2014 at 7:55
  • Right, i've edited and remove the group and attribute... :) Commented Jul 30, 2014 at 14:40
  • Is this have space Tunneling: User? Commented Jul 31, 2014 at 16:35
  • Yes there is a space between TUnneling: and User. Commented Aug 1, 2014 at 9:37
  • The last line in your input doesn't? Commented Aug 1, 2014 at 9:38

2 Answers 2

1

Try this:

$ 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 
1
  • don't work ... the file 1 does not contain attribute, just the source IP, the date and time . if in both file, source IP, date and time are matching then the output should be: 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 Commented Jul 31, 2014 at 16:20
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 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.