I have to count how many users were logged in each day of the week. I can get the data with the last command on the server, but how can I process it with awk? It is a long list of data, the name of the day is in the 4th column. I declared an array like this: t["Sun"]=0; t["Sat"]=0; etc, I can count it from a simple input from the terminal, but how can I use it on the output of last?
If I log in the server and type: last, I get a result like this, each row containing the name of the user, pts/something, ip address, day of the week, time etc:
user pts/0 address Mon etc.
user pts/1 address Wed etc.
I'd like an output like this:
Mon: 10 users were logged in
Tue: 20 user were logged in etc
My code is here, which works with an input from terminal:
awk '
BEGIN { t["Sun"]=0; t["Sat"]=0; t["Fri"]=0; t["Thu"]=0; t["Wed"]=0; t["Tue"]=0; t["Mon"]=0; }
{ t[substr($4,i,3)]++;}
END {for(i in t) print i ": " t[i]}
'$*
So far to an input in terminal like this:
aa ss dd Fri
a d g Mon
q w e Fri
gives the result:
Wed: 0
Tue: 0
Fri: 2
Thu: 0
Sat: 0
Sun: 0
Mon: 1
How can I use the awk command to process the output of last?