![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Figure out complex sort | w020637 | Shell Programming and Scripting | 7 | 02-05-2009 03:13 PM |
| sort data in different columns | mogabr | Shell Programming and Scripting | 15 | 08-04-2008 07:07 AM |
| Manage Complex XML Data in Oracle XML DB 11g | iBot | Oracle Updates (RSS) | 0 | 04-06-2008 06:10 AM |
| Script to sort data | wizardy_maximus | Shell Programming and Scripting | 1 | 11-21-2007 04:30 AM |
| sort data | bjorb | Shell Programming and Scripting | 11 | 09-15-2005 06:22 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
hi, i think perl should be a right and easy solution.
Code:
#!/usr/bin/perl
sub sub_sort{
my @t1=split("[(|)]",$_[0]);
my @t2=split("[(|)]",$_[1]);
if($t1[1] == $t2[1]){
return $t1[0] cmp $t2[0];
}
else{
return $t2[1] <=> $t1[1];
}
}
open FH,"<a.txt";
while(<FH>){
chomp;
my @temp=split(" ",$_);
print $temp[0]," ", join " ",sort { sub_sort($a,$b) } @temp[1..$#temp];
print "\n";
}
|
|
|||||
|
Nice catch summer_cherry, I did not notice that the OP wants to sort twice (first numeric, then ascii/utf8), so I need to modify the code:
Code:
perl -lane'
print join " ", shift @F, sort {
($aa) = $a =~ /(\d+)/;
($bb) = $b =~ /(\d+)/;
$bb <=> $aa || $a cmp $b
} @F
' infile
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|