Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!uwvax!dogie.macc.wisc.edu!indri!polyslo!csun!srhqla!uucp From: comp-mail-mush@srhqla.uucp Newsgroups: comp.mail.mush Subject: Re: Mush 6.5 man page suggestions Message-ID: <654@srhqla.UUCP> Date: 18 May 89 00:51:37 GMT Sender: uucp@srhqla.UUCP Lines: 130 From: Marc Rouleau On May 16, 16:02, "Barton E. Schaefer" wrote: > > } 7. Personal preference - the list of curses commands currently is > } printed across the columns; would you consider listing them > } down columns? > > Do you know of any unix utility that will automatically sort them down > the columns? I don't want to do it by hand and I can't find anything > that will do it for me. Ls, pr, and friends all columnate across. Hmm, ls -C on every Unix system I've used sorts down columns, not across. But I don't see how you could use it to sort your list of curses commands anyway. I do agree with Larry Virden that it's easier to read a columnated list when it's sorted down the columns ... For what it's worth, here's a little script I've been using privately (in somewhat less spiffy form :-) ) for a while to do that very thing. -- Marc Rouleau ----------------------------- cut here ------------------------------ #!/usr/bin/perl eval "exec /usr/bin/perl -S $0 $*" if $running_under_some_shell; # colsort [-i] [-n numcols | -w width] [files] # # This script sorts and columnates its input. Output is ordered _down_ # the columns. # # Like sed(1), it takes its input from specified files if they exist and # from stdin if they do not. # # The -i option causes it to ignore case during the sort. # # The -n option takes a single argument which is the number of output # columns. In this case the columns will be tab-separated presumably # for tbl(1) fodder. # # The -w option takes a single argument which is the width of the output # "page". In this case the columns will be visually aligned in the # manner of ls(1). # # The -n and -w options are mutually exclusive. The default behavior # is equivalent to "-w 64". # # BUGS: Since the sorting is done in core, I doubt this will work on very # large input sets. # # -- Marc Rouleau (marc@virginia.edu) $USAGE = "colsort [-i] [-n numcols | -w width] [files]\n"; sub IgnoreCase { $x = $a; $y = $b; $x =~ tr/A-Z/a-z/; $y =~ tr/A-Z/a-z/; $x lt $y ? -1 : $x gt $y ? 1 : 0; } sub NumericArg { if (!/([0-9]+)/) { shift; } else { $1; } } while ($_ = $ARGV[0],/^-/) { shift; if (/^-i/) { $IGNORECASE = 1; } elsif (/^-n/) { $NUMPERLINE = do NumericArg(); } elsif (/^-w/) { $WIDTH = do NumericArg(); } } if ($NUMPERLINE && $WIDTH) { print $USAGE; exit 1; } if (!$NUMPERLINE && !$WIDTH) { $WIDTH = 64; } for ($i = 0, $Longest = 0; <>; $i++) { $words[$i] = $_; $Longest = length($_) - 1 > $Longest ? length($_) - 1 : $Longest; } if ($IGNORECASE) { @sortedwords = sort IgnoreCase @words; } else { @sortedwords = sort @words; } if ($WIDTH) { if ($NUMPERLINE = $WIDTH / $Longest) { $NUMPERLINE -= $WIDTH % $Longest < $NUMPERLINE - 1 ? 1 : 0; } else { $NUMPERLINE = 1; } } $NumWords = $#sortedwords + 1; $Extra = $NumWords % $NUMPERLINE; $Extra = $Extra ? $Extra : $NUMPERLINE; $NumLines = int(($NumWords / $NUMPERLINE) + ($Extra ? 1 : 0)); for ($i = 0; $i < $NumLines; $i++) { $column = 1; for ($j = $i; $j < $NumWords; $j += $j_inc) { $word = $sortedwords[$j]; chop($word); print "$word"; if ($NUMPERLINE == 1) { print "\n"; } elsif ($WIDTH) { print ' ' x ($Longest - length($word) + 1); } else { print "\t"; } last if ($column == $Extra && $i == ($NumLines-1)); $j_inc = ($NumLines - ($column++ <= $Extra ? 0 : 1)); } print "\n"; }