Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Pulling out oldest entries from a text file

by sgt (Deacon)
on Sep 05, 2007 at 08:38 UTC ( #637087=note: print w/replies, xml ) Need Help??

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

    Log In?

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://637087]
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (4)
    As of 2023-10-04 07:26 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found