On Mon, Jun 15, 2009 at 11:49:41AM -0400, Chas. Owens wrote: > On Mon, Jun 15, 2009 at 11:28, Aimee Cardenas<aim...@sfbrgenetics.org> wrote: > > Hi, All! > > > > I have a file with two important columns in it separated by spaces. I'll > > call these col1 and col2. I need to sort the data by col2 and then print > > col1 & col2 to a file. I know I CAN do it with perl, but which way is > > faster for this kind of processing? Perl or Awk? I know with awk, I can > > find a one-liner for the command line and I could probably do that with > > perl, too (I'm just now refreshing myself on perl command line options), but > > I just thought I'd get some experienced opinions on the best way to do it. > > > > Thanks in advance. May your sky be filled with perly clouds! ;-) > > > > Aimee > > Sounds like a job for a Schwartzian Transform[1]:
Another option: perl -lane 'push @f, [...@f[0,1]]; END { print "@$_" for sort { $a->[1] cmp $b->[1] } @f}' A better option: cut -f1,2 | sort -k2 -- Paul Johnson - p...@pjcj.net http://www.pjcj.net -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/