• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to do you get rid off the duplicate name?

 
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to figure out how to eliminated the duplicate of name using the linux last command.
 
Marshal
Posts: 4812
604
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic