{section: TJ's simple scripts} {subsection: 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. {file: sort_ads.pl} #!/usr/bin/env perl use strict; use warnings; my %ad; for my $line ( ) { if ($line =~ /^\s*$/) { # print out the previous add sorted by key then reset the hash for a new ad. if (%ad) { for (sort keys %ad) { print $_; } undef %ad; } } $ad{$line} = 1; } # print the last ad sorted by key if (%ad) { for (sort keys %ad) { print $_; } undef %ad; } {endfile} Example {term} condor_status -long | perl sort_ads.pl {endterm}