• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to do you get rid off the duplicate name?  RSS feed

 
jin Otanashi
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure out how to eliminated the duplicate of name using the linux last command.
 
Ron McLeod
Bartender
Posts: 1603
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may not be the best solution, but maybe use it a starting point for something better:

     last | awk '/^wtmp/ || /^$/ {next;} !seen[$1]++ {print $1}'

It will return a list of unique usernames (field 1) while maintaining order.  It also removes the blank line and the line beginning with wtmp which is included in the command output.  Remove {print $1} if you want to see the whole line.
 
jin Otanashi
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:This may not be the best solution, but maybe use it a starting point for something better:

     last | awk '/^wtmp/ || /^$/ {next;} !seen[$1]++ {print $1}'

It will return a list of unique usernames (field 1) while maintaining order.  It also removes the blank line and the line beginning with wtmp which is included in the command output.  Remove {print $1} if you want to see the whole line.

awk isn't the only way of doing this ?
I know that awk is one way but somehow this will go out of bound or may miss some date using the shell scripts or any programming languages.
 
jin Otanashi
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Go out of bound or may miss some data using the shell scripts or using  any programming languages.
Perhaps a linked list or a data structures may work with this but I don't know for sure how this thing will work without the awk.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!