Code:
$
$
$ cat f4
No Start End
A 22,222,33,22,1233,3232,44 555,333,222,55,1235,3235,66
B 33,333,22,44 66,340,44,55
C 66,55,555 75,58,560
$
$
$
$ perl -lane 'if ($. > 1) {
@x=split(/,/,$F[1]);
@y=split(/,/,$F[2]);
for $i (0..$#x) {push @z,"$x[$i]~$y[$i]"}
@idx1 = (); @idx2 = ();
for (@z) {
($key1, $key2) = /(\d+)~(\d+)/;
push @idx1, $key1;
push @idx2, $key2;
}
@sorted = @z[sort{$idx1[$a]<=>$idx1[$b] || $idx2[$a]<=>$idx2[$b]} 0..$#z];
@x=(); @y=();
foreach (@sorted) {/(\d+)~(\d+)/ && push(@x,$1) && push(@y,$2)}
print "$F[0] ",join(",",@x)," ",join(",",@y);
@x=(); @y=(); @z = (); @new = ();
} else {print}
' f4
No Start End
A 22,22,33,44,222,1233,3232 55,555,222,66,333,1235,3235
B 22,33,44,333 44,66,55,340
C 55,66,555 58,75,560
$
$