Reputation: 13
I have the following tabel:
^2num^5|^2score^5|^2ping^5 | ^2status ^5| ^2name players ^5| ^2address
---- ------- ------ -------- -------------------- -----------------------^7
^5 0 ^2|^3 41 ^2|^3 100 ^2|^5 Player ^2|^7Just a Cr4zy name! ^2|^77.18.76.12:58641 ^3[^5FR^3]^7
^5 2 ^2|^3 3 ^2|^3 57 ^2|^3 Bot ^2|^7^8bot1 ^2|^7bot
^5 3 ^2|^3 7 ^2|^3 43 ^2|^3 Bot ^2|^7^8bot2 ^2|^7bot
^5 4 ^2|^3 18 ^2|^3 16 ^2|^3 Bot ^2|^7^8bot3 ^2|^7bot
^5 5 ^2|^3 2 ^2|^3 103 ^2|^5 Player ^2|^7Just a ^5Cr4zy n4me2! ^2|^784.18.8.144:27960 ^3[^5IL^3]^7
^5 6 ^2|^3 18 ^2|^3 102 ^2|^3 Bot ^2|^7^8bot4 ^2|^7bot
^5 7 ^2|^3 29 ^2|^3 102 ^2|^3 Bot ^2|^7^8bot5 ^2|^7bot
^5 8 ^2|^3 39 ^2|^3 54 ^2|^3 Bot ^2|^7^8bot ^2|^7bot
^5 9 ^2|^3 24 ^2|^3 77 ^2|^3 Bot ^2|^7^8bot ^2|^7bot
^510 ^2|^3 10 ^2|^3 103 ^2|^3 Bot ^2|^7^8bot ^2|^7bot
^511 ^2|^3 42 ^2|^3 95 ^2|^3 Bot ^2|^7^8bot ^2|^7bot
^512 ^2|^3 2 ^2|^3 103 ^2|^5 Player ^2|^7Ju5t a ^5Cr4zy ^7name3! ^2|^722.185.55.9:13565 ^3[^5IL^3]^7
^513 ^2|^3 24 ^2|^3 96 ^2|^3 Bot ^2|^7^8bot ^2|^7bot
^514 ^2|^3 0 ^2|^3 51 ^2|^3 Bot ^2|^7^8bot ^2|^7bot
^2-------------------------------------------------------------------------^7
^5Bots : ^311 ^5, Players : ^33 ^5, All : ^314
I would like to grab the info per line: num and address Every column starts and ends with a color code i do not need. Like in column 1, it starts with ^5 and ends with ^2 The lines with a bot can also be skipped.
output i prefer:
0 77.18.76.12
5 84.18.8.144
12 22.185.55.9
Seperate i would like to have the number of players as displayed in the last line.
preferable with sed, grep or awk
Thank you very much in advance.
Upvotes: 0
Views: 92
Reputation: 37404
In awk:
$ awk 'match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}/) {
print substr($0,3,2),substr($0,RSTART,RLENGTH) }
0 77.18.76.12
5 784.18.8.144
12 722.185.55.9
If there is an ip looking string in the record, print
it and characters 3 and 4 from the beginning of the record. Naturally will fail if player uses an ip address as name.
A separate script to count the players:
$ awk 'match($0,/([0-9]{1,3}\.){3}[0-9]{1,3}/) {
i++ } # player counter
END{ print "Players : " i+0 }' file
Upvotes: 2