Unix/Linux Go Back    



Sort command in one column and not effect to another column

UNIX for Dummies Questions & Answers




Kindly Note - This is a Single User Post by Forum Member radoulov Regarding:
Sort command in one column and not effect to another column.
Please Follow The Primary Link Above to View the Full Discussion.

   
Old Unix and Linux 03-22-2013
radoulov's Unix or Linux Image
radoulov radoulov is offline Forum Advisor  
Forum Adviser
 
Join Date: Jan 2007
Last Activity: 9 January 2017, 4:40 AM EST
Location: Варна, България / Milano, Italia
Posts: 5,690
Thanks: 184
Thanked 629 Times in 586 Posts

Code:
perl -F'\s*=\s*' -lane'
  push @f, $F[0];
  push @s, $F[1];
  END {
    @ss = sort { $a <=> $b } @s;
    for (sort { $a <=> $b } @f) {
      printf "%s = %s\n", $_, shift @ss 
      }    
    }' infile

Or (if your shell supports process substitution):


Code:
paste -d= <(cut -d= -f1 infile | sort -n) <(cut -d= -f2 infile | sort -n)


Last edited by radoulov; 03-22-2013 at 08:09 AM..
The Following User Says Thank You to radoulov For This Useful Post:
GeodusT (03-22-2013)