find information about logins

Hi, all
I want to make a bash script that print all users from a system using last command.
I want to print the number of user's login in the format (descending order):

5   user1    address1
4   user2    address2

I am trying the command

last | awk '{print $1 " " $3}' | sort | uniq

but it is not run as I want

Could you help me ??

use this command

last | sed -r 's/[ \t]+/ /g'  | cut -d ' ' -f 1,3 | sort | uniq

Awk version:

 last | awk '/./ {$0=++c " " $1 "  " $2}1;' | tac

Thanks a lot for your quick answer.

The problem I have is that I have to count the number of logins and sort by number then.

last | tr -s " " | cut -d ' ' -f 1,3 | sort | uniq

Thanks for your help

I check the sort and uniq parameters and I found it.

This awk command might work for you:

last -d | awk '/./{print $1, $3}' | sort -n -k1 | uniq -w1 -c

It does not print all the users.

I pass the output of command

last | sed -r 's/[ \t]+/ /g'  | cut -d ' ' -f 1,3 | uniq -c | sort -nr

in a file

And I am trying to something like adding the first number when the user is the same :

cat "a.txt" | while read line; do
        userName= awk '{print $2}'
        ip =awk '{print $3}'

        counter=0

        if grep $userName userLoginInfo.txt
        then
                Number1=expr 'awk{print $1}'
                counter=expr `Number1 + counter`
        fi

        echo "$counter $UserName $ip"
done

But something I do wrong.

You can try this instead to get the number of users pr.terminal/sessions:

last -i -F | awk '/./{print $1, $2, $3}' | sort  | uniq  -c | sort -r -n

Thanks jostber