I'm having trouble sorting on the *last* word of the last field in a record.
The details;
number of fields = 2
Field separator = :
First field alsways has one word
Second field has variable number of words
Example:
adjn:Joshua Ng
adktk:KaLap Timothy Kwong
admg:Mahalingam Gobieramanan
admln:Martha L. Nangalama
admrp:Michael R. Pearson
adshl:Siu Lung Henry Lee
adsyh:So Yi Ho
adtkk:Tariq K. Khan
adtkl:Terence K. H. Leung
advld:Vickie L. Dwyer
alaen:Alfred E. Neuman
anedp:Erin D. Picard
I want to sort on the last word of field #2.
I haven't been able to figure out how to do this with sort(1). Any awk,
sed, perl or other suggestions and/or pointers would be most welcome.
Thanks!
--
Ken Brown internet: kbr...@trentu.ca
Trent University Computing & Telecommunications tel: (705)748-1540
Peterborough, Ontario, Canada, K9J 7B8 fax: (705)748-1635
--
Disclaimer: I don't speak for Martin Marietta or the EPA.
----------------------------------------------------------
dfru...@unixmail.rtpnc.epa.gov, Martin Marietta TSI,
P.O. Box 14365, MD-4501-1B, Research Triangle Park, NC 27709
sed 's/\(.* \)\(.*\)/\2:\1/' /tmp/tst | sort -t: | sed 's/\([^:]*\):\(.*\)/\2\1/'
Ed Allen
--
--
i don't really KNOW, |Ed Allen
|Wilcox Electric Inc.
i just make it up as i go |2001 NE 46 Street
|Kansas City Missouri, 64116
>>>>> "Ken" == Ken Brown <cc...@dakhma.trentu.ca> writes:
Ken> Hello,
Ken> I'm having trouble sorting on the *last* word of the last field in a record.
Ken> The details;
Ken> number of fields = 2
Ken> Field separator = :
Ken> First field alsways has one word
Ken> Second field has variable number of words
Ken> Example:
Ken> adjn:Joshua Ng
Ken> adktk:KaLap Timothy Kwong
Ken> admg:Mahalingam Gobieramanan
Ken> admln:Martha L. Nangalama
Ken> admrp:Michael R. Pearson
Ken> adshl:Siu Lung Henry Lee
Ken> adsyh:So Yi Ho
Ken> adtkk:Tariq K. Khan
Ken> adtkl:Terence K. H. Leung
Ken> advld:Vickie L. Dwyer
Ken> alaen:Alfred E. Neuman
Ken> anedp:Erin D. Picard
Ken> I want to sort on the last word of field #2.
Ken> I haven't been able to figure out how to do this with sort(1). Any awk,
Ken> sed, perl or other suggestions and/or pointers would be most welcome.
Speak with a lisp in Perl, I'd write it like this:
#!/usr/bin/perl
require 5; # new features, new bugs!
print
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [$_, /(\S+)$/] }
<>;
print "Just another Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <mer...@stonehenge.com> Snail: (Call) PGP-Key: (finger mer...@ora.com)
Phrase: "Welcome to Portland, Oregon ... home of the California Raisins!"
>Speak with a lisp in Perl, I'd write it like this:
> #!/usr/bin/perl
> require 5; # new features, new bugs!
> print
> map { $_->[0] }
> sort { $a->[1] cmp $b->[1] }
> map { [$_, /(\S+)$/] }
> <>;
Please explain, how it works!
I tried to figure out, but I didn't get it.
I'm not yet very familiar with the *special* features of perl5.
How would you do it in perl4?
Thanks Dirk
--
biafra@acab.[isdn.cs.tu|in]-berlin.de (Dirk Jaeckel)
GCS d--->---- H s+:- g+ !p au* a- w+ v(?) C++ USL++++$ P+++ L++
3+>++ E--- N++>+++ K- W---- M !V p--- Y+>++ t++@ 5- !j G?
tv++>! b++ D--- B? e+ u* h+(--) f+ r- !n y?