Sort two columns with alphanumeric values horizontally

Hi, I have a file like

aa	bb	dmns|860	dmns|756	ee	ff
aa	bb	dmns|310	dmns|260	ee	ff
aa	bb	dmns|110	dmns|77	ee	ff
aa	bb	dmns|756	dmns|860	ee	ff
aa	bb	dmns|110	dmns|77	ee	ff
aa	bb	dmns|233	dmns|79	ee	ff
aa	bb	dmns|79	dmns|233	ee	ff

I want to sort the values in column3 and column4 horizontally. Rest column will be fixed after sorting.
Here is the desired output

aa	bb	dmns|756	dmns|860	ee	ff
aa	bb	dmns|260	dmns|310	ee	ff
aa	bb	dmns|77	dmns|110	ee	ff
aa	bb	dmns|756	dmns|860	ee	ff
aa	bb	dmns|77	dmns|110	ee	ff
aa	bb	dmns|79	dmns|233	ee	ff
aa	bb	dmns|79	dmns|233	ee	ff

I tried these with no success

awk -F, '{print $3, $4}' file | sort -V | sed 's/^[0-9][0-9]* //'

awk -F, '{print $3, $4}' file | sort -n -k1.6 | sed 's/^[0-9][0-9]* //'

awk '{print $3, $4}' test_filter_by_score.txt | perl -ane '$,=" "; print sort @F; print "\n";' 

Hello sammy777888,

Considering that your Input_file is same as shown sample Input_file, if that is the case then following may help you in same.

awk -F"\t" '{sub(/ /,"",$3);split($3,a,"|");q=a[2];v=a[3];sub(/[0-9]+/,"",q);sub(/[0-9]+/,"",v);if(a[2]+0>a[3]+0){tmp=a[2]+0;a[2]=a[3]+0;a[3]=tmp+0};$3=sprintf("%s|%d%s%s|%d%s%s",a[1],a[2]+0,length(a[2]+0)>2?"":" ",q,a[3]+0,length(a[3]+0)>2?"":" ",v)}1' OFS="\t"  Input_file
 

Output will be as follows.

aa      bb      dmns|756dmns|860ee      ff
aa      bb      dmns|260dmns|310ee      ff
aa      bb      dmns|77 dmns|110ee      ff
aa      bb      dmns|756dmns|860ee      ff
aa      bb      dmns|77 dmns|110ee      ff
aa      bb      dmns|79 dmns|233ee      ff
aa      bb      dmns|79 dmns|233ee      ff

EDIT: Adding a non-one liner form of solution too now.

awk -F"\t" '{
    sub(/ /,"",$3);
    split($3,a,"|");
    q=a[2];
    v=a[3];
    sub(/[0-9]+/,"",q);
    sub(/[0-9]+/,"",v);
    if(a[2]+0>a[3]+0){
        tmp=a[2]+0;
        a[2]=a[3]+0;
        a[3]=tmp+0
};
    $3=sprintf("%s|%d%s%s|%d%s%s",a[1],a[2]+0,length(a[2]+0)>2?"":" ",q,a[3]+0,length(a[3]+0)>2?"":" ",v)
}
1
' OFS="\t"   Input_file
 

Thanks,
R. Singh

Try also

awk '
        {T = " " $3 "  " $4
         gsub (/ [^|]*\|/, _, T)
         split (T, TN)
         if (TN[1] > TN[2])     {T  = $3
                                 $3 = $4
                                 $4 = T
                                }
        }
1
' OFS="\t" file
aa	bb	dmns|756	dmns|860	ee	ff
aa	bb	dmns|260	dmns|310	ee	ff
aa	bb	dmns|77	dmns|110	ee	ff
aa	bb	dmns|860	dmns|756	ee	ff
aa	bb	dmns|77	dmns|110	ee	ff
aa	bb	dmns|79	dmns|233	ee	ff
aa	bb	dmns|233	dmns|79	ee	ff