Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Command line file sorting

by artist (Parson)
on Sep 05, 2007 at 17:48 UTC ( #637223=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-12-06 21:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?