develooper Front page | perl.beginners | Postings from May 2008

Sorting and grouping question

Thread Next
From:
ANJAN PURKAYASTHA
Date:
May 15, 2008 10:13
Subject:
Sorting and grouping question
Hi,
here is a problem I'm working on. It's not PERL-specific, rather it is a
problem in sorting followed by grouping.
Suppose I have a set of lines that have tab-delimited text, thus:
1  w   3   wer
2  a   4    rte
4  w   2    weg
6  d  4    fhg
5  d   7   dfl
6  w   4   ald
8  a   3   dsl

I would like to first sort the lines based on the 2nd token (w,a, w, d, etc)
and then group the lines based on the 2nd token.

At the end of this sorting/grouping I should have the lines grouped thus:
2  a   4    rte
8   a   3   dsl

6   d  4    fhg
5   d   7   dfl

1  w   3   wer
4  w   2    weg
6  w   4   ald


I can figure out the sorting. Are they any command/modules to do the
grouping based on identical tokens?

appreciate your input.


tia,
anjan



-- 
ANJAN PURKAYASTHA, PhD.
Senior Computational Biologist
==========================

1101 King Street, Suite 310,
Alexandria, VA 22314.
703.518.8040 (office)
703.740.6939 (mobile)

email:
anjan@vbi.vt.edu;
anjan.purkayastha@gmail.com

http://www.vbi.vt.edu

==========================


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About