On Tue, Mar 12, 2002 at 04:36:38AM +0900, Ed Baker wrote: > If I have an array of data, where each record looks like the example > below the cut line, how could I do a "uniq" sort based only on the > first column. > > ===========================cut line ======================== > 100788 1000 1538 > 100791 1000 1505 > 100791 1000 1520 > 100792 1000 1698 > 100792 1000 5215 > 100802 1000 1088 > 100808 1000 1094 > 100827 1000 1516 > 100829 1000 1115 > 100830 1000 1115 > 100891 1000 1398 > 100895 1000 1115 def myUniq(strings) last = nil; strings.delete_if do |s| this = s.split[0] sameAsLast = (last != nil and this == last) last = this sameAsLast end end sample = ["100788 1000 1538", "100791 1000 1505", "100791 1000 1520", "100792 1000 1698", "100792 1000 5215", "100802 1000 1088", "100808 1000 1094", "100827 1000 1516", "100829 1000 1115", "100830 1000 1115", "100891 1000 1398", "100895 1000 1115"] puts myUniq(sample); -> 100788 1000 1538 100791 1000 1505 100792 1000 1698 100802 1000 1088 100808 1000 1094 100827 1000 1516 100829 1000 1115 100830 1000 1115 100891 1000 1398 100895 1000 1115 -- marko schulz