Classificar com base no campo1, campo2, mas preservando o campo 1 classificando e ignorando nulos / espaços em branco no segundo tipo

5

Depois de trabalhar muito em casa e executar vários cenários de teste, decidi obter ajuda de especialistas

Aqui está o meu cenário

Dados de entrada após a classificação pela coluna 1

-bash-3.2$ sort -t'|' -k1  -k2 clm.srt
"1033CLMS0400000000000"||""|"0000000558             "|     |1
"2020000005438WC011631"||""|"              200606202"|     |2
"2020000005438WC011632"|10|"N"|"20060626N00000200000"|10   |3
"2020000005438WC011632"|11|"N"|"20060626N00000200000"|11   |4
"2020000005438WC011632"|12|"N"|"20060626N00000200000"|12   |5
"2020000005438WC011632"|1|"N"|"20060620N000020000000"|1    |13
"2020000005438WC011632"|47|"N"|"20060626N00000000000"|47   |43
"2020000005438WC011632"|5|"N"|"20060626N000000000000"|5    |45
"2020000005438WC011632"|6|"N"|"20060626N0002N0200000"|6    |46
"2020000005438WC011632"|7|"N"|"20060626N000002N00000"|7    |47
"2020000005438WC011632"|8|"N"|"20060626N000000200000"|8    |48
"2020000005438WC011632"|9|"N"|"20060626N0000N0200000"|9    |49
"2020000005438WC011633"||""|"20060605000            "|     |50
"2020000005438WC011634"||""|"001033720061           "|     |51
"2020000005438WC011635"||""|"0020060626N+00014000000"|     |52

Se eu forçar o ordenamento numérico no 2º campo, os valores em branco serão colocados no topo, o que perturba o primeiro tipo de campo

-bash-3.2$ sort -t'|' -k1 -n -k2 clm.srt
"1033CLMS0400000000000"||""|"0000000558             "|     |1
"2020000005438WC011631"||""|"              200606202"|     |2
"2020000005438WC011633"||""|"20060605000            "|     |50
"2020000005438WC011634"||""|"001033720061           "|     |51
"2020000005438WC011635"||""|"0020060626N+00014000000"|     |52
"2020000005438WC011632"|1|"N"|"20060620N000020000000"|1    |13
"2020000005438WC011632"|5|"N"|"20060626N000000000000"|5    |45
"2020000005438WC011632"|6|"N"|"20060626N0002N0200000"|6    |46
"2020000005438WC011632"|7|"N"|"20060626N000002N00000"|7    |47
"2020000005438WC011632"|8|"N"|"20060626N000000200000"|8    |48
"2020000005438WC011632"|9|"N"|"20060626N0000N0200000"|9    |49
"2020000005438WC011632"|10|"N"|"20060626N00000200000"|10   |3
"2020000005438WC011632"|11|"N"|"20060626N00000200000"|11   |4
"2020000005438WC011632"|12|"N"|"20060626N00000200000"|12   |5
"2020000005438WC011632"|47|"N"|"20060626N00000000000"|47   |43

Idealmente, eu estava tentando conseguir isso

"1033CLMS0400000000000"||""|"0000000558             "|     |1
"2020000005438WC011631"||""|"              200606202"|     |2
"2020000005438WC011632"|1|"N"|"20060620N000020000000"|1    |13
"2020000005438WC011632"|5|"N"|"20060626N000000000000"|5    |45
"2020000005438WC011632"|6|"N"|"20060626N0002N0200000"|6    |46
"2020000005438WC011632"|7|"N"|"20060626N000002N00000"|7    |47
"2020000005438WC011632"|8|"N"|"20060626N000000200000"|8    |48
"2020000005438WC011632"|9|"N"|"20060626N0000N0200000"|9    |49
"2020000005438WC011632"|10|"N"|"20060626N00000200000"|10   |3
"2020000005438WC011632"|11|"N"|"20060626N00000200000"|11   |4
"2020000005438WC011632"|12|"N"|"20060626N00000200000"|12   |5
"2020000005438WC011632"|47|"N"|"20060626N00000000000"|47   |43
"2020000005438WC011633"||""|"20060605000            "|     |50
"2020000005438WC011634"||""|"001033720061           "|     |51
"2020000005438WC011635"||""|"0020060626N+00014000000"|     |52

Por favor, sugira

Cumprimentos Suresh

    
por Suresh Narasimha 25.03.2015 / 04:51

1 resposta

6

Você precisa especificar onde as chaves de classificação terminarão. Caso contrário, eles terminam no final da linha.

E para aplicar classificação numérica a apenas uma chave, com n anexado à especificação principal. -n sozinho transformaria a classificação numérica globalmente.

sort -t'|' -k1,1 -k2,2n
    
por 25.03.2015 / 07:51