1

Short version of issue:
Need to extract from logs: {Using sed and awk on Linux}
Time, PlayerName{Can have many special characters}, GUID, IP from log example at end.

Longer version:
How to combine 2 log file lines IF the player number at “near” point in time match next line.

This number is only valid till player disconnect.
The number will then be used by new player.
This creates a special problem illustrated with: Player #106 being 4 lines, yet refer to two different players.

Progress this far.
Reading manuals and forums. Already extracting individual data fields and write these to mysql.

But, I really need to log data together as one relevant:
What player with what IP and what GUID connected at what time.
This data can only be obtained by combining two lines if player number match near point in time as I can see.

Example of log:

23:57:20 : Player #29 Simplename (10.21.23.32:2304) connected  
23:57:22 : Player #29 Simplename - GUID: 1234567890abcdef123456789aaaaa00 (unverified)
23:56:13 : Player #106 [Som(e) name]  Gabriel (10.21.23.33:2304) connected  
23:56:15 : Player #106 [Som(e) name]  Gabriel - GUID: 1234567890abcdef123456789bbbbb00 (unverified)  
23:56:51 : Player #106 [gp0] SomeN@me 123  (10.21.23.34:2304) connected  
23:56:52 : Player #106 [gp0] SomeN@me 123  - GUID: 1234567890abcdef123456789aaaaa02 (unverified)  
23:57:18 : Player #20 [gp0] SomeN@me 123  (10.21.23.44:2304) connected  
23:57:19 : Player #20 [gp0] SomeN@me 123  - GUID: 1234567890abcdef123456789aaaaa03 (unverified)  
23:57:51 : Player #6 <<t>> 'N@me5_Can=Be..Hard (10.21.23.32:2304) connected  
23:57:53 : Player #6 <<t>> 'N@me5_Can=Be..Hard - GUID: 1234567890abcdef123456789aaaaa04 (unverified)  
  • see my answer, are second player 106 and player 20 same ? (different GUID) – Archemar Apr 17 '16 at 7:40
2

assuming IP and GUID have fixed position

/connected/ {
  name = substr($0,index($0,$4)+length($4)+1) ;
  nip=NF-1 ;
  name = substr(name,1,index(name,$nip)-2) ;
  session[$4]=name ;
  connected[name]=$0 ;
  ip[name]=$nip ;
}

/GUID/ {
  if ( $4 in session ) {
    ngu = NF-1 ;
    guid=$ngu ;
    printf "%s - %s - %s -%s\n",$1,session[$4],guid,ip[session[$4]] ;

    delete session[$4] ;
  }

}
  • no white in IP, GUID ...
  • name is captured upon connection
  • I took time from GUID line, registering connection time can be saved the same way as for IP.
  • I left as exercice to remove ( :2304) from IP ...

as a result

23:57:22 - Simplename - 1234567890abcdef123456789aaaaa00 -(10.21.23.32:2304)
23:56:15 - [Som(e) name]  Gabriel - 1234567890abcdef123456789bbbbb00 -(10.21.23.33:2304)
23:56:52 - [gp0] SomeN@me 123  - 1234567890abcdef123456789aaaaa02 -(10.21.23.34:2304)
23:57:19 - [gp0] SomeN@me 123  - 1234567890abcdef123456789aaaaa03 -(10.21.23.44:2304)
23:57:53 - <<t>> 'N@me5_Can=Be..Hard - 1234567890abcdef123456789aaaaa04 -(10.21.23.32:2304)

Note:

  • session #99 can be interwoven, but not with same number.
  • code can be change to join on player name instead.

BUT

  • you cannot mix session number AND have same player name.
  • Thank you very much. Your code work. I was trying with some but little success. awk -F" " '{ prev=$0; f1=$1; f4=$4; f5=$5; f6=$6; getline if ($4 == f4) { #print prev $1 #print $1 print f1, f4, f5, f6, $6, $7, $8 } }' file Working through your code to try and understand why it works. – fun6utzi Apr 17 '16 at 10:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.