{"id":967,"date":"2019-04-19T17:25:02","date_gmt":"2019-04-19T09:25:02","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=967"},"modified":"2022-05-14T19:02:38","modified_gmt":"2022-05-14T11:02:38","slug":"sort","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/sort","title":{"rendered":"sort\u547d\u4ee4 – \u5bf9\u6587\u4ef6\u5185\u5bb9\u8fdb\u884c\u6392\u5e8f"},"content":{"rendered":"\n
sort\u547d\u4ee4\u7684\u529f\u80fd\u662f\u5bf9\u6587\u4ef6\u5185\u5bb9\u8fdb\u884c\u6392\u5e8f\u3002\u6709\u65f6\u6587\u672c\u4e2d\u7684\u5185\u5bb9\u987a\u5e8f\u4e0d\u6b63\u786e\uff0c\u4e00\u884c\u884c\u5730\u624b\u52a8\u4fee\u6539\u5b9e\u5728\u592a\u9ebb\u70e6\u4e86\u3002\u6b64\u65f6\u4f7f\u7528sort\u547d\u4ee4\u5c31\u518d\u5408\u9002\u4e0d\u8fc7\u4e86\uff0c\u5b83\u80fd\u591f\u5bf9\u6587\u672c\u5185\u5bb9\u8fdb\u884c\u518d\u6b21\u6392\u5e8f\u3002<\/p>\n\n\n\n
\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>sort [\u53c2\u6570] \u6587\u4ef6<\/p>\n\n\n\n \u5e38\u7528\u53c2\u6570\uff1a\ufeff<\/strong><\/p>\n\n\n\n \u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n \u5bf9\u6307\u5b9a\u7684\u6587\u4ef6\u5185\u5bb9\u6309\u7167\u5b57\u6bcd\u987a\u5e8f\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n\n\n\n \u5bf9\u6307\u5b9a\u7684\u6587\u4ef6\u5185\u5bb9\u6309\u7167\u6570\u5b57\u5927\u5c0f\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n\n\n\n \u4ee5\u5192\u53f7\uff08\uff1a\uff09\u4e3a\u95f4\u9694\u7b26\uff0c\u5bf9\u6307\u5b9a\u7684\u6587\u4ef6\u5185\u5bb9\u6309\u7167\u6570\u5b57\u5927\u5c0f\u5bf9\u7b2c3\u5217\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n\n\n\n sort\u547d\u4ee4\u7684\u529f\u80fd\u662f\u5bf9\u6587\u4ef6\u5185\u5bb9\u8fdb\u884c\u6392\u5e8f\u3002\u6709\u65f6\u6587\u672c\u4e2d\u7684\u5185\u5bb9\u987a\u5e8f\u4e0d\u6b63\u786e\uff0c\u4e00\u884c\u884c\u5730\u624b\u52a8\u4fee\u6539\u5b9e\u5728\u592a\u9ebb\u70e6\u4e86\u3002\u6b64\u65f6\u4f7f\u7528so […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/967"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=967"}],"version-history":[{"count":21,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/967\/revisions"}],"predecessor-version":[{"id":9686,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/967\/revisions\/9686"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=967"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=967"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=967"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}-b<\/td> \u5ffd\u7565\u6bcf\u884c\u524d\u9762\u5f00\u59cb\u51fa\u7684\u7a7a\u683c\u5b57\u7b26<\/td><\/tr> -c<\/td> \u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5df2\u7ecf\u6309\u7167\u987a\u5e8f\u6392\u5e8f<\/td><\/tr> -d<\/td> \u9664\u5b57\u6bcd\u3001\u6570\u5b57\u53ca\u7a7a\u683c\u5b57\u7b26\u5916\uff0c\u5ffd\u7565\u5176\u4ed6\u5b57\u7b26<\/td><\/tr> -f<\/td> \u5c06\u5c0f\u5199\u5b57\u6bcd\u89c6\u4e3a\u5927\u5199\u5b57\u6bcd<\/td><\/tr> -i<\/td> \u9664040\u81f3176\u4e4b\u95f4\u7684ASCII\u5b57\u7b26\u5916\uff0c\u5ffd\u7565\u5176\u4ed6\u5b57\u7b26<\/td><\/tr> -m<\/td> \u5c06\u51e0\u4e2a\u6392\u5e8f\u53f7\u7684\u6587\u4ef6\u8fdb\u884c\u5408\u5e76<\/td><\/tr> -M<\/td> \u5c06\u524d\u97623\u4e2a\u5b57\u6bcd\u4f9d\u7167\u6708\u4efd\u7684\u7f29\u5199\u8fdb\u884c\u6392\u5e8f<\/td><\/tr> -n<\/td> \u4f9d\u7167\u6570\u503c\u7684\u5927\u5c0f\u6392\u5e8f<\/td><\/tr> -o <\u8f93\u51fa\u6587\u4ef6><\/td> \u5c06\u6392\u5e8f\u540e\u7684\u7ed3\u679c\u5b58\u5165\u5236\u5b9a\u7684\u6587\u4ef6<\/td><\/tr> -r<\/td> \u4ee5\u76f8\u53cd\u7684\u987a\u5e8f\u6765\u6392\u5e8f<\/td><\/tr> -t <\u5206\u9694\u5b57\u7b26><\/td> \u6307\u5b9a\u6392\u5e8f\u65f6\u6240\u7528\u7684\u680f\u4f4d\u5206\u9694\u5b57\u7b26<\/td><\/tr> -k<\/td> \u6307\u5b9a\u9700\u8981\u6392\u5e8f\u7684\u680f\u4f4d<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n [root@linuxcool ~]# cat fruit.txt <\/strong>\r\nbanana\r\npear\r\napple\r\norange\r\nraspaberry\r\n[root@linuxcool ~]# sort fruit.txt <\/strong>\r\napple\r\nbanana\r\norange\r\npear\r\nraspaberry<\/pre>\n\n\n\n
[root@linuxprobe ~]# cat number.txt <\/strong>\n45\n12\n3\n98\n82\n67\n24\n56\n9\n[root@linuxprobe ~]# sort -n number.txt <\/strong>\n3\n9\n12\n24\n45\n56\n67\n82\n98<\/pre>\n\n\n\n
[root@linuxprobe ~]# sort -t : -k 3 -n user.txt <\/strong>\r\nrpc:x:32:32:Rpcbind Daemon\r\ntss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon\r\nqemu:x:107:107:qemu user\r\nusbmuxd:x:113:113:usbmuxd user\r\npulse:x:171:171:PulseAudio System Daemon\r\nrtkit:x:172:172:RealtimeKit\r\ngluster:x:995:990:GlusterFS daemons\r\nunbound:x:996:991:Unbound DNS resolver\r\ngeoclue:x:997:995:User for geoclue\r\npolkitd:x:998:996:User for polkitd\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n","protected":false},"excerpt":{"rendered":"