in reply to text sorting question, kinda
#!/usr/bin/perl -l print for map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [$_, ( /blahblah/ ? 0 : 1 ) . $_] } <>;
It uses a Schwartzian Transform that compares the second elements of an array looking like this:
The lines that don't match the regex get prepended with a 0 and the ones that do match get a 1. That way the matching lines always win a cmp with the non-matching ones.( ["bat 1 blahblah", "1bat 1 blahblah"], ["foo 2 blahblah", "1foo 2 blahblah"], ["bar 1 zot", "0bar 1 zot"], ["bar 2 zot", "0bar 2 zot"] )
Here's a shorter, faster one using substr instead of arrays:
#!/usr/bin/perl -l print for map { substr($_, 1) } sort map { ( /blahblah/ ? 0 : 1 ) . $_ } <>;
-Matt
|
|---|