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 |
This is a bit of a hack, but it works: :D
Code:
tac datafile | awk '{if ($1==y || $1=="User") print; y=$1}' | tac |
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. |