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
두 번째 필드에 숫자 정렬을 강제로 적용하면 공백 값이 맨 위로 밀려 첫 번째 필드 정렬을 방해하게 됩니다.
-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
이상적으로 나는 이것을 달성하려고 노력하고 있습니다.
"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
답변1
정렬 키가 끝나는 위치를 지정해야 합니다. 그렇지 않으면 줄 끝에서 끝납니다.
하나의 키에만 숫자 정렬을 적용하려면 n
이를 키 사양에 추가하세요. -n
Alone은 전역적으로 숫자 정렬을 켭니다.
sort -t'|' -k1,1 -k2,2n