Tuesday, 3 March 2015

UNIX sort

sortRequestFiles("/tmp/input");

sub sortRequestFiles {
$INPUT_DIR = $_[0];

my @files = glob( "$INPUT_DIR/request*" );

foreach (@files ){
   print "Sorting " . $_ . "\n";
   qx/head -n1 $_ > $_.tmp/;
    qx/tail -n +2 $_ | sort -k1,1 -nk2 >> $_.tmp/;
    qx/mv $_.tmp $_/;
  
    }

           }

No comments:

Post a Comment