Page History

Turn Off History

sort_ads.pl

A script to sort a collection of classads by key without reordering the ads. What it actually does is accumulate lines from stdin until it gets to a blank line, then prints out those lines sorted and clears the collection.
sort_ads.pl
#!/usr/bin/env perl
use strict;
use warnings;

my %ad;

for my $line ( <STDIN> ) {

  if ($line =~ /^\s*$/) {
    # print out the hash
    if (%ad) {
       for (sort keys %ad) { print $_; }
       undef %ad;
    }
  }
  $ad{$line} = 1;

}

if (%ad) {
   for (sort keys %ad) { print $_; }
   undef %ad;
}
Example
condor_status -long | perl sort_ads.pl