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


in reply to Command line file sorting

*nix :
dirdata:
dir-100-1
dir-100-10
dir-100-2
dir-100-9
dir-100-99
dir-2-1
dir-28-1
dir-29-1
dir-29-2
dir-30-1
dir-3-1
Sorting: sort -rnt - -k2 -k3 dirdata <br> Selecting 2nd entry: sort -rnt - -k2 -k3 dirdata | head -2 | tail -1

Replies are listed 'Best First'.
Re^2: Command line file sorting
by swkronenfeld (Hermit) on Sep 05, 2007 at 18:34 UTC
    artist

    Thanks. I was playing with sort earlier, and was unable to make this work properly. Your solution still has one problem that I need to address, something that I didn't mention above. If there is only one entry, the entry sometimes* gets printed, but I need that result to be empty. Is there an easy way to do this from the shell?

    * - I say sometimes, because on bash under linux, it does not get printed due to an extra blank line that somehow gets generated in the output. On AIX and MacOS X, the entry gets printed.
      Following should not print anything, if there is no data in the 2nd line.
      cat data | awk NR==2
      --Artist