#!usr/bin/perl use strict; use warnings; my @lines; while (<DATA>) { push @lines,$_; } @lines = sort by_col2 @lines; print @lines; sub by_col2 { my ($A_col2) = (split ' ', $a)[1]; my ($B_col2) = (split ' ', $b)[1]; $A_col2 cmp $B_col2; } =prints 912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912810RS9 Bond 30-Year 2016-05-12 2016-05-16 2046-0 +5-15 97.619462 2.500000 912810RQ3 Bond 29-Year 2016-04-14 2016-04-15 2046-0 +2-15 98.011430 2.500000 912828Q86 Note 1-Year 2016-05-25 2016-05-27 2018-0 +4-30 100.003850 NULL 912828N71 Note 9-Year 2016-05-19 2016-05-31 2026-0 +1-15 103.533587 0.625000 =cut __DATA__ 912828Q86 Note 1-Year 2016-05-25 2016-05-27 2018-0 +4-30 100.003850 NULL 912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912810RS9 Bond 30-Year 2016-05-12 2016-05-16 2046-0 +5-15 97.619462 2.500000 912810RQ3 Bond 29-Year 2016-04-14 2016-04-15 2046-0 +2-15 98.011430 2.500000 912796HD4 Bill 4-Week 2016-01-26 2016-01-28 2016-0 +2-25 99.977056 NULL 912828N71 Note 9-Year 2016-05-19 2016-05-31 2026-0 +1-15 103.533587 0.625000
In reply to Re: File content sorting based on type
by Marshall
in thread File content sorting based on type
by perlmad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |