Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 373  / 1 Year ago, wed, january 4, 2023, 4:08:00

I have the following text lines:



.add 7971 [Player: Sunfire (Account: 11309) X: 5839.623047 Y: 600.437439 Z: 650.839722 Map: 571 Selected player: Llubia (GUID: 19369)]  
.add 43956 [Player: Sunfire (Account: 11309) X: 5277.887695 Y: 2862.181641 Z: 446.735931 Map: 571 Selected none: (GUID: 0)]
.add 43956 [Player: Sunfire (Account: 11309) X: 5281.407715 Y: 2864.844482 Z: 446.735931 Map: 571 Selected player: Staticbaby (GUID: 19826)]
.add 43956 [Player: Sunfire (Account: 11309) X: 5231.464844 Y: 1437.029175 Z: 648.498535 Map: 571 Selected player: Sunfire (GUID: 15295)]
.add 44077 [Player: Sunfire (Account: 11309) X: 5231.464844 Y: 1437.029175 Z: 648.498535 Map: 571 Selected player: Sunfire (GUID: 15295)]
.add 49285 [Player: Sunfire (Account: 11309) X: 16225.323242 Y: 16252.759766 Z: 12.790466 Map: 1 Selected none: (GUID: 0)]
.add 44115 175 [Player: Elmasguapo (Account: 11309) X: 1659.845093 Y: -4198.589844 Z: 56.382870 Map: 1 Selected none: (GUID: 0)]
.add 34078 [Player: Sunfire (Account: 11309) X: 16227.969727 Y: 16280.081055 Z: 13.175169 Map: 1 Selected none: (GUID: 0)]
.add |cffffffff|Hitem:41427:0:0:0:0:0:0:0:80|h[Fuego de Artificio de Dalaran]|h|r 50 [Player: Sunfire (Account: 11309) X: 16221.392578 Y: 16260.944336 Z: 13.255954 Map: 1 Selected none: (GUID: 0)]
.add |cffffffff|Hitem:45932:0:0:0:0:0:0:0:80|h[Gelatina Negra]|h|r [Player: Sunfire (Account: 11309) X: 5874.347168 Y: 679.056763 Z: 167.483719 Map: 571 Selected player: Assasins (GUID: 19438)]
.add |cffffffff|Hitem:45932:0:0:0:0:0:0:0:80|h[Gelatina Negra]|h|r [Player: Sunfire (Account: 11309) X: 5873.767090 Y: 679.386841 Z: 167.435257 Map: 571 Selected player: Assasins (GUID: 19438)]
.add |cffffffff|Hitem:45932:0:0:0:0:0:0:0:80|h[Gelatina Negra]|h|r [Player: Sunfire (Account: 11309) X: 16226.880859 Y: 16247.247070 Z: 12.286857 Map: 1 Selected player: Irmtarget (GUID: 18521)]
.add |cffffffff|Hitem:45932:0:0:0:0:0:0:0:80|h[Gelatina Negra]|h|r [Player: Sunfire (Account: 11309) X: 16229.297852 Y: 16251.202148 Z: 13.081388 Map: 1 Selected player: Irmtarget (GUID: 18521)]
.add 41600 2 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]
.add 41600 1 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]
.add 40516 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]
.add 44661 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]
.add 40518 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]
.add 44005 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]
.add 45867 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]
.add 45316 [Player: Sunfire (Account: 11309) X: 16223.138672 Y: 16250.496094 Z: 12.431313 Map: 1 Selected player: Eifreen (GUID: 20341)]


And I want to parse it so it outputs something like this:



Line 1 For example - 7971 Llubia

Line 3 For example - 43956 Staticbaby

Line 9 For Example - 45932 Assassins



And so on.. This is done in the terminal with commands like cut, grep, cat, etc..



UPDATE: Here is the whole file: http://paste2.org/p/1744102 to parse in that way.



UPDATE2: Please forgive me if I do not accept an answer just yet. Am waiting for the bounty option to appear since for me, stuff like this deserve a bounty. So I will add a bounty and give it to the correct answer or answers.


More From » 11.10

 Answers
6
awk '
# ignore lines with "none:" or "player:" in $(NF-2)
$(NF-2) ~ /^(none|player):$/ {
next # read next line
}

{
# remove dots from $2 in every line
gsub(/./,"",$2)
}

/|Hitem:/ {
# if it has "|Hitem:" in $2, remove everything
# before and after the colons
sub(/.+|Hitem:/,"",$2)
sub(/:.+/,"",$2)
print $2,$(NF-2)
next # read next line
}

{
print $2,$(NF-2)
}
' your_file.txt


Line 380 has Selected player: (GUID: 6873)]. You have to decide what to do with such lines (ignore them? print the GUID instead?).


[#42474] Wednesday, January 4, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
homerurhyth

Total Points: 338
Total Questions: 113
Total Answers: 105

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;