{"id":214294,"date":"2021-03-31T09:18:35","date_gmt":"2021-03-31T01:18:35","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=214294"},"modified":"2021-03-22T10:19:04","modified_gmt":"2021-03-22T02:19:04","slug":"linux-sort-ling","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-sort-ling.html","title":{"rendered":"\u5b66\u4e60\u4e00\u4e2a Linux \u547d\u4ee4\uff1asort \u547d\u4ee4"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u4eca\u5929\u6765\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e00\u4e0blinux\u7684sort\u547d\u4ee4<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

1.\u547d\u4ee4\u7b80\u4ecb<\/strong><\/div>\n

\u4ee5\u884c\u4e3a\u5355\u4f4d\u5bf9\u6587\u672c\u6587\u4ef6\u7684\u5185\u5bb9\u8fdb\u884c\u6392\u5e8f\uff0c\u5c06\u7ed3\u679c\u663e\u793a\u5728\u6807\u51c6\u8f93\u51fa\uff0c\u6bd4\u8f83\u539f\u5219\u662f\u4ece\u884c\u9996\u5b57\u7b26\u5411\u540e\uff0c\u4f9d\u6b21\u6309 ASCII \u7801\u503c\u8fdb\u884c\u6bd4\u8f83\uff0c\u6700\u540e\u6309\u5347\u5e8f\u8f93\u51fa\u3002\u5982\u679c file \u53c2\u6570\u6307\u5b9a\u591a\u4e2a\u6587\u4ef6\uff0c\u90a3\u4e48 sort \u547d\u4ee4\u5c06\u8fd9\u4e9b\u6587\u4ef6\u7eb5\u5411\u8fde\u63a5\u8d77\u6765\uff0c\u5f53\u4f5c\u4e00\u4e2a\u6587\u4ef6\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n

\u4e0d\u52a0\u4efb\u4f55\u9009\u9879\u65f6\uff0c\u5c06\u5bf9\u6574\u884c\u4ece\u7b2c\u4e00\u4e2a\u5b57\u7b26\u5f00\u59cb\u4f9d\u6b21\u5411\u540e\u76f4\u5230\u884c\u5c3e\u6309\u7167 ASCII \u7801\u503c\u505a\u5347\u5e8f\u6392\u5e8f\u3002<\/p>\n

2.\u547d\u4ee4\u683c\u5f0f<\/strong><\/div>\n
sort [OPTION]... [FILE]...\r\nsort [OPTION]... --files0-from=F<\/pre>\n
3.\u9009\u9879\u8bf4\u660e<\/strong><\/div>\n

\u6ce8\u610f\uff0c\u957f\u9009\u9879\u7684\u5f3a\u5236\u6027\u53c2\u6570\u5bf9\u4e8e\u77ed\u9009\u9879\u4e5f\u662f\u5f3a\u5236\u7684\u3002<\/p>\n

-b, --ignore-leading-blanks\r\n \u5ffd\u7565\u6bcf\u884c\u524d\u9762\u7684\u7a7a\u683c\u5b57\u7b26\r\n-c, --check, --check=diagnose-first\r\n \u53ea\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5df2\u6392\u5e8f\uff0c\u4e0d\u8fdb\u884c\u6392\u5e8f\r\n-C, --check=quiet, --check=silent\r\n \u7c7b\u4f3c\u4e8e -c\uff0c\u4f46\u4e0d\u62a5\u544a\u7b2c\u4e00\u4e2a\u4e71\u5e8f\u7684\u884c\r\n-d, --dictionary-order\r\n \u6309\u7167\u5b57\u5178\u5e8f\uff0c\u53ea\u8003\u8651\u5b57\u6bcd\u3001\u6570\u5b57\u53ca\u7a7a\u683c\u5b57\u7b26\uff0c\u5ffd\u7565\u5176\u4ed6\u5b57\u7b26\r\n--files0-from=F\r\n \u4ece\u6587\u4ef6 F \u4e2d\u4ee5 NUL \u5b57\u7b26\u7ed3\u5c3e\u7684\u5b57\u7b26\u4e32\u4f5c\u4e3a\u8f93\u5165\u6587\u4ef6\u540d\uff1b\u5982\u679c F \u662f -\uff0c\u5219\u4ece\u6807\u51c6\u8f93\u5165\u4e2d\u8bfb\u53d6\u6587\u4ef6\u540d\r\n-f, --ignore-case\r\n \u6392\u5e8f\u65f6\uff0c\u5c06\u5c0f\u5199\u5b57\u6bcd\u89c6\u4e3a\u5927\u5199\u5b57\u6bcd\r\n-i, --ignore-nonprinting\r\n \u6392\u5e8f\u65f6\uff0c\u53ea\u8003\u8651\u53ef\u6253\u5370\u5b57\u7b26\uff0c\u5ffd\u7565\u4e0d\u53ef\u6253\u5370\u5b57\u7b26\r\n-m, --merge\r\n \u5408\u5e76\u591a\u4e2a\u5df2\u6392\u5e8f\u7684\u6587\u4ef6\r\n-n, --numeric-sort\r\n \u6309\u6570\u503c\u5927\u5c0f\u6392\u5e8f\r\n-o, --output=FILE\r\n \u5c06\u6392\u5e8f\u7ed3\u679c\u8f93\u51fa\u5230\u6307\u5b9a\u6587\u4ef6\r\n-r,--reverse\r\n \u9006\u5411\u8f93\u51fa\u6392\u5e8f\u7ed3\u679c\uff08\u964d\u5e8f\u6392\u5e8f\uff09\r\n-t, --field-separator=SEP\r\n \u6307\u5b9a\u6392\u5e8f\u65f6\u4f7f\u7528\u7684\u5206\u9694\u5b57\u7b26\uff0csort\u547d\u4ee4\u9ed8\u8ba4\u5b57\u6bb5\u5206\u9694\u7b26\u4e3a\u7a7a\u683c\u548cTab\r\n-u, --unique\r\n \u76f8\u540c\u7684\u6570\u636e\u4e2d\uff0c\u4ec5\u8f93\u51fa\u4e00\u884c\r\n-k,--key=POS1[,POS2]\r\n \u4ee5\u7b2c POS1 \u680f\u5230 POS2 \u680f\u6392\u5e8f\uff0c\u9ed8\u8ba4\u5230\u6700\u540e\u4e00\u680f\r\n--help\r\n \u663e\u793a\u5e2e\u52a9\u4fe1\u606f\u5e76\u9000\u51fa\r\n--version\r\n \u663e\u793a\u7248\u672c\u4fe1\u606f\u5e76\u9000\u51fa<\/pre>\n
4.\u5e38\u7528\u793a\u4f8b<\/strong><\/div>\n
\uff081\uff09\u5bf9 \/etc\/passwd \u8fdb\u884c\u6392\u5e8f\u3002<\/strong><\/span><\/div>\n
cat \/etc\/passwd | sort\r\nadm:x:3:4:adm:\/var\/adm:\/sbin\/nologin\r\napache:x:48:48:Apache:\/var\/www:\/sbin\/nologin\r\nbin:x:1:1:bin:\/bin:\/sbin\/nologin\r\ndaemon:x:2:2:daemon:\/sbin:\/sbin\/nologin<\/pre>\n
\uff082\uff09\/etc\/passwd \u5185\u5bb9\u4ee5\u5192\u53f7:\u6765\u5206\u9694\uff0c\u4ee5\u7b2c\u4e09\u680f\u81f3\u884c\u672b\u5c3e\u680f\u6765\u6392\u5e8f\u3002<\/strong><\/span><\/div>\n
cat \/etc\/passwd | sort -t ':' -k 3\r\nroot:x:0:0:root:\/root:\/bin\/bash\r\nuucp:x:10:14:uucp:\/var\/spool\/uucp:\/sbin\/nologin\r\noperator:x:11:0:operator:\/root:\/sbin\/nologin\r\nbin:x:1:1:bin:\/bin:\/sbin\/nologin\r\ngames:x:12:100:games:\/usr\/games:\/sbin\/nologin<\/pre>\n
\uff083\uff09\u5982\u679c\u5bf9 \/etc\/passwd\uff0c\u4ee5\u7b2c\u516d\u4e2a\u57df\u7684\u7b2c 2 \u4e2a\u5b57\u7b26\u5230\u7b2c 4 \u4e2a\u5b57\u7b26\u8fdb\u884c\u5347\u5e8f\u6392\u5e8f\uff0c\u518d\u57fa\u4e8e\u7b2c\u4e00\u4e2a\u57df\u8fdb\u884c\u53cd\u5411\u6392\u5e8f\u3002<\/strong><\/span><\/div>\n
cat \/etc\/passwd | sort -t ':' -k 6.2,6.4 -k 1,1r\r\nsync:x:4:65534:sync:\/bin:\/bin\/sync\r\nproxy:x:13:13:proxy:\/bin:\/bin\/sh\r\nbin:x:2:2:bin:\/bin:\/bin\/sh\r\nsys:x:3:3:sys:\/dev:\/bin\/sh\r\nbin:x:3:3:sys:\/dev:\/bin\/sh<\/pre>\n

\u53ef\u4ee5\u770b\u51fa\uff0c\u516d\u4e2a\u57df\u7684\u7b2c 2 \u4e2a\u5b57\u7b26\u5230\u7b2c 4 \u4e2a\u5b57\u7b26\u662f\u5347\u5e8f\u6392\u5e8f\u3002\u516d\u4e2a\u57df\u7684\u7b2c 2 \u4e2a\u5b57\u7b26\u5230\u7b2c 4 \u4e2a\u5b57\u7b26\u5982\u679c\u76f8\u540c\u5219\u5206\u4e3a\u4e00\u7ec4\uff0c\u7ec4\u5185\u518d\u6309\u7167\u7b2c\u4e00\u4e2a\u57df\u8fdb\u884c\u964d\u5e8f\u6392\u5e8f\u3002\u6ce8\u610f\uff0c-r \u9700\u8981\u4e0e\u7b2c\u4e8c\u4e2a -k \u7684 <POS1,POS2> \u8fde\u5199\uff0c\u5426\u5219\u5bf9\u524d\u9762\u4e24\u4e2a -k \u5747\u6709\u6548\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4ee5\u884c\u4e3a\u5355\u4f4d\u5bf9\u6587\u672c\u6587\u4ef6\u7684\u5185\u5bb9\u8fdb\u884c\u6392\u5e8f\uff0c\u5c06\u7ed3\u679c\u663e\u793a\u5728\u6807\u51c6\u8f93\u51fa\uff0c\u6bd4\u8f83\u539f\u5219\u662f\u4ece\u884c\u9996\u5b57\u7b26\u5411\u540e\uff0c\u4f9d\u6b21\u6309 ASCII \u7801\u503c\u8fdb […]<\/p>\n","protected":false},"author":1469,"featured_media":214297,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-214294","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/214294","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1469"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=214294"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/214294\/revisions"}],"predecessor-version":[{"id":214298,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/214294\/revisions\/214298"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/214297"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=214294"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=214294"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=214294"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}