http://qs321.pair.com?node_id=637087


in reply to Pulling out oldest entries from a text file

What does happen when you get two identical dates?

As you don't say anything about the context, supposing unix-like, I thought I could mention various one-liners to get a feeling of your data:

  • UN*X golf. It is always worth playing with your system sort as it is often optimized for speed.
  • a Minimal Perl approach.
  • % steph@apexPDell2 (/home/stephan/t) % % cat data.txt # I added the last line + item group entry_date 34 gr1 2003-03-02 12 gr1 1990-03-14 39 gr3 2002-04-11 66 gr4 2006-03-16 32 gr3 1998-02-13 90 gr1 2004-06-15 55 gr4 1999-06-15 10 gr1 2003-03-02 % steph@apexPDell2 (/home/stephan/t) % % LC_ALL=C sort -k 3 data.txt | perl -lna -e 'print if $F[1] eq q{gr1} + and $F[0] == 34' 34 gr1 2003-03-02 % steph@apexPDell2 (/home/stephan/t) % % sort -k 3 data.txt | grep gr1 | sort -n | head -n1 10 gr1 2003-03-02

    The last one reads as sort on the date, select group gr1, select on the first numerically and keep tghe first line. In this particular case it is faster to grep first.

    cheers --stephan