I have a file with next format
2011-12-01 user1 access1
2011-12-01 user1 access2
2011-12-01 user2 access2
2011-12-01 user4 access2
2011-12-02 user1 access1
2012-01-01 user3 access1
2012-01-01 user4 access2
I would like to have an output that for every user shows the last date, so
2011-12-02 user1 access1
2011-12-01 user1 access2
2011-12-01 user2 access2
2012-01-01 user3 access1
2012-01-01 user4 access2
I tried something like this:
less myfile.txt | sort -k1r | uniq -f 1 | sort -b -k1
but it isn't seems to work right.
Thank you for help!
cat
, notless
. Somebody will now surely point out thatcat myfile | sort
is worse thansort myfile
, but I find it easier when having long pipe sequences. – Ulrich Schwarz Jan 25 '12 at 12:42<myfile sort | uniq | sort
keeps the logical order while not introducing a spurious process. – Gilles 'SO- stop being evil' Jan 25 '12 at 23:20