LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple problem, parsing. (https://www.linuxquestions.org/questions/programming-9/simple-problem-parsing-611868/)

cizzi 01-07-2008 07:32 PM

Simple problem, parsing.
 
I have this sample data:

User Sent Received
root 241 168
root 0 2350
root 980 1072
root 0 4510
root 4943 7137
root 1238000 684862
root 0 3420
root 0 236
root 1244164 703755
www-data 4065 884
www-data 1280 1428
www-data 101127 5790
www-data 106472 8102
irc 11267 9386
irc 11267 9386
nobody 312 0
nobody 208 0
nobody 240 0
nobody 40 0
nobody 200 0
nobody 1000 0
cizzi 9386 11267
cizzi 9386 11267

My goal is to have the same output *without* the subtotals of each users, notice the last entry of each user sums the sent/received columns. How can we do this with either sed, awk, c, or any other linux tool? I know its simple but I spent a few hours and can't get it right. Any help would be appreciated.

Just to clarify it, the output should look like this

User Sent Received Flags
root 241 168
root 0 2350
root 980 1072
root 0 4510
root 4943 7137
root 1238000 684862
root 0 3420
root 0 236
www-data 4065 884
www-data 1280 1428
www-data 101127 5790
irc 11267 9386
nobody 312 0
nobody 208 0
nobody 240 0
nobody 40 0
nobody 200 0
cizzi 9386 11267

jozyba 01-07-2008 08:06 PM

This is a bit of a hack, but it works: :D
Code:

tac datafile | awk '{if ($1==y || $1=="User") print; y=$1}' | tac
EDIT::mad: I just realised that if a user only has one entry it get's deleted - back to the drawing board...

cizzi 01-07-2008 08:17 PM

It worked! Thank you so much. I spent 3 hours writting C code without success :)


All times are GMT -5. The time now is 02:39 PM.