이 정렬이 +/- 문자 접두어를 무시하는 이유는 무엇입니까?

이 정렬이 +/- 문자 접두어를 무시하는 이유는 무엇입니까?

특정 변경 사항을 강조하기 위해 패치를 정렬하려고 합니다.

$ curl -s https://lists.fedorahosted.org/archives/list/[email protected]/message/ZN6VMFN65JWV7NMG2XEHPUI2AGSLRNGW/attachment/2/0001-LDAP-Change-the-default-rfc2307-autofs-attribute-map.patch | \
grep '^[+-] *{ "' | sort

출력은 다음과 같습니다

-    { "ldap_autofs_entry_object_class", "automount", SYSDB_AUTOFS_ENTRY_OC, NULL },
+    { "ldap_autofs_entry_object_class", "nisObject", SYSDB_AUTOFS_ENTRY_OC, NULL },
-    { "ldap_autofs_entry_value", "automountInformation", SYSDB_AUTOFS_ENTRY_VALUE, NULL },
+    { "ldap_autofs_entry_value", "nisMapEntry", SYSDB_AUTOFS_ENTRY_VALUE, NULL },
+    { "ldap_autofs_map_name", "nisMapName", SYSDB_AUTOFS_MAP_NAME, NULL },
-    { "ldap_autofs_map_name", "ou", SYSDB_AUTOFS_MAP_NAME, NULL },
-    { "ldap_autofs_map_object_class", "automountMap", SYSDB_AUTOFS_MAP_OC, NULL },
+    { "ldap_autofs_map_object_class", "nisMap", SYSDB_AUTOFS_MAP_OC, NULL },

정렬이 첫 번째 문자 +/-로 정렬되기를 원했을 것입니다.

문자가 0x2b 및 0x2d로 일치하는지 확인할 수 있습니다.

$ curl -s https://lists.fedorahosted.org/archives/list/[email protected]/message/ZN6VMFN65JWV7NMG2XEHPUI2AGSLRNGW/attachment/2/0001-LDAP-Change-the-default-rfc2307-autofs-attribute-map.patch | grep '^[+-] *{ "' | cut -c1 | hexdump -C

00000000  2d 0a 2d 0a 2b 0a 2b 0a  2d 0a 2b 0a 2d 0a 2b 0a  |-.-.+.+.-.+.-.+.|
00000010

sort -d동일한 결과를 제공합니다. -d+/-는 영숫자를 의미하지만 +/-는 영숫자를 의미하지 않습니다. sort -n작동하지 않습니다(작동할 것으로 기대하지 않습니다.)

나는 인정하고 싶은 것보다 오랫동안 Linux/Unix를 사용해 왔지만 이전에는 이것을 본 적이 없습니다!

...예상된 일인가요? 그것을 사용하는 다른 방법이 있나요 sort? (Perl oneliner에서도 가능하다는 것을 알고 있습니다...)

답변1

에서 언급했듯이ls 정렬이 영숫자가 아닌 문자를 무시하는 이유는 무엇입니까?, 기본 데이터 정렬은 UTF8이고 UTF8은 +/- 동등한 것으로 간주됩니다.

정렬을 설정하면 LC_COLLATE=CASCII 정렬 순서를 얻을 수 있습니다.

curl -s https://lists.fedorahosted.org/archives/list/[email protected]/message/ZN6VMFN65JWV7NMG2XEHPUI2AGSLRNGW/attachment/2/0001-LDAP-Change-the-default-rfc2307-autofs-attribute-map.patch | \
grep '^[+-] *{ "' | LC_COLLATE=C sort

관련 정보