Awk script to add times.

Hey,

Im trying to format the last command to tell me just the user names, logins, and the time that they were logged in. So far I got the users logins using a loop that counts the amount of times a user logged in but im not sure how to start the time array. The time im trying to use is the last field when the last command is entered. Any help would be appreciated.

Here is some code I have atm:

BEGIN{print "USER" "\t" "LOGINS" "\t" "TIME"}
{count[$1]++}
END {
        for (name in count)
         print name "\t   " count[name]
}

Thanks for reading.

I presume you want to display cumulative times for each user? Try using the split() function to pull out the components of the time field, and convert it to minutes, and add it to time[$1]. Then convert it back to d+hh:mm format when you are ready to print it.

Sounds like a homework assignment I once had. :smiley: