bah! L~R beat me to it again..

in the spirit of TIMTOWTDI...

..note I've swapped '\t' for ',' to make it easily copy/pasted..

#!/usr/bin/perl my %hash; while(<DATA>){ chomp; my @line = split /,/; my $first = shift @line; push( @{$hash{$first}}, @line ); } foreach( sort keys %hash ){ print "$_\t".join(' ', sort @{$hash{$_}})."\n"; } __DATA__ text1,text-a,text-w text2,text-b,text-y text3,text-x,text-t text1,text-d,text-n text3,text-f,text-z text3,text-e,text-w text10,word,other 1 text10,aword,nother 1 text11,cword,tother 1 text11,zword,bother 1 __END__ prints: text1 text-a text-d text-n text-w text10 aword nother 1 other 1 word text11 bother 1 cword tother 1 zword text2 text-b text-y text3 text-e text-f text-t text-w text-x text-z

Update: hmm.. this version doesn't produce the lines in the order it found them (it sorts but the first word in the line), but that's easily changed if required as per the other examples..

cheers,

J


In reply to Re: Problems sorting by edoc
in thread Problems sorting by dr_jgbn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.