{"id":2297,"date":"2011-01-19T19:19:49","date_gmt":"2011-01-19T11:19:49","guid":{"rendered":"http:\/\/edsionte.com\/techblog\/?p=2297"},"modified":"2011-10-12T09:09:44","modified_gmt":"2011-10-12T01:09:44","slug":"cut%e5%92%8cpaste","status":"publish","type":"post","link":"http:\/\/edsionte.com\/techblog\/archives\/2297","title":{"rendered":"cut\u547d\u4ee4\u548cpaste\u547d\u4ee4"},"content":{"rendered":"<h6><span class=\"Apple-style-span\" style=\"font-size: 13px;\">cut\u547d\u4ee4<\/span><\/h6>\n<p>\u987e\u540d\u601d\u4e49\uff0ccut\u547d\u4ee4\u5c31\u662f\u4ece\u6587\u672c\u6587\u4ef6\u6216\u4ece\u67d0\u4e2a\u547d\u4ee4\u7684\u8f93\u51fa\u6570\u636e\u4e2d\u88c1\u526a\uff08\u6790\u53d6\uff09\u51fa\u60f3\u8981\u7684\u6570\u636e\u57df\u3002cut\u547d\u4ee4\u4e00\u822c\u4f7f\u7528\u7684\u65b9\u5f0f\u4e3a\uff1a<\/p>\n<p><strong>cut -cchars file<\/strong><\/p>\n<p>\u5176\u4e2d\uff0c-cchar\u4e2d\u7684-c\u4e3acut\u547d\u4ee4\u7684\u5e38\u7528\u9009\u9879\uff0c\u8868\u793a\u4ecefile\u6587\u4ef6\u7684<strong>\u6bcf\u4e00\u884c<\/strong>\u4e2d\u90fdcut\u51fachars\u8fd9\u6bb5\u6587\u5b57\u3002\u3002chars\u7684\u53d6\u503c\u8f83\u4e3a\u7075\u6d3b\uff0c\u5206\u4e3a\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u3002<\/p>\n<p>cut -c5 file\uff1a\u6790\u53d6file\u6587\u4ef6\u6bcf\u884c\u7684\u7b2c5\u4e2a\u5b57\u7b26\uff1b<\/p>\n<p>cut -c5,7 file\uff1a\u6790\u53d6file\u6587\u4ef6\u6bcf\u884c\u7b2c5\u548c\u7b2c7\u4e2a\u5b57\u7b26\uff1b<\/p>\n<p>cut -c6-8 file\uff1a\u6790\u53d6file\u6587\u4ef6\u6bcf\u884c\u7b2c6\u5230\u7b2c8\u4e2a\u5b57\u7b26\uff1b<\/p>\n<p>cut -c6- file\uff1a\u6790\u53d6file\u6587\u4ef6\u6bcf\u884c\u7b2c6\u4e2a\u5230\u884c\u5c3e\u4e4b\u95f4\u7684\u5b57\u7b26\uff1b<\/p>\n<p>cut -c-3 file\uff1a\u6790\u53d6file\u6587\u4ef6\u6bcf\u884c\u884c\u9996\u5230\u7b2c\u4e09\u4e2a\u5b57\u7b26\u4e4b\u95f4\u7684\u5b57\u7b26\uff1b<\/p>\n<p>\u5982\u679ccut\u547d\u4ee4\u4e2d\u672a\u6307\u5b9afile\uff0c\u5219\u5c06\u6807\u51c6\u8f93\u5165\u4f5c\u4e3acut\u547d\u4ee4\u7684\u6790\u53d6\u5bf9\u8c61\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~$ ls -l\r\n\u603b\u7528\u91cf 1680\r\ndrwx------  2 edsionte edsionte   4096 2011-01-10 20:38 android_code\r\n-rwxrwxrwx  1 edsionte edsionte   7138 2011-01-13 08:42 a.out\r\ndrwxr-xr-x  2 edsionte edsionte   4096 2011-01-16 21:46 assembly\r\ndrwxr-xr-x  2 edsionte edsionte   4096 2011-01-11 09:58 bin\r\ndrwx------ 24 edsionte edsionte   4096 2011-01-17 11:35 code\r\nedsionte@edsionte-desktop:~$ ls -l | cut -c1-9\r\n\u603b\u7528\u91cf\r\ndrwx-----\r\n-rwxrwxrw\r\ndrwxr-xr-\r\ndrwxr-xr-\r\ndrwx-----<\/pre>\n<p>\u4e0a\u8ff0cut\u547d\u4ee4\u4e2d\uff0c\u5c06ls\u547d\u4ee4\u7684\u8f93\u51fa\u4f5c\u4e3acut\u547d\u4ee4\u7684\u8f93\u5165\u3002\u4ea7\u751f\u7684\u7ed3\u679c\u662f\u6790\u53d6\u51fa\u6bcf\u5217\u6570\u636e\u7684\u7b2c1\u5230\u7b2c9\u4e2a\u5b57\u7b26\uff0c\u4e5f\u65e2\u662f\u6bcf\u4e2a\u6587\u4ef6\u7684\u8bbf\u95ee\u6743\u9650\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u901a\u8fc7\u9017\u53f7\u9694\u5f00\u4e24\u4e2a\u6570\u503c\u5217\u8868\uff0c\u5206\u522b\u6790\u53d6\u51fa\u6587\u4ef6\u8bbf\u95ee\u6743\u9650\u548c\u6587\u4ef6\u540d\u3002<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~$ ls -l\r\n\u603b\u7528\u91cf 1680\r\ndrwx------  2 edsionte edsionte   4096 2011-01-10 20:38 android_code\r\n-rwxrwxrwx  1 edsionte edsionte   7138 2011-01-13 08:42 a.out\r\ndrwxr-xr-x  2 edsionte edsionte   4096 2011-01-16 21:46 assembly\r\ndrwxr-xr-x  2 edsionte edsionte   4096 2011-01-11 09:58 bin\r\ndrwx------ 24 edsionte edsionte   4096 2011-01-17 11:35 code\r\nedsionte@edsionte-desktop:~$ ls -l | cut -c1-9,56-\r\n\u603b\u7528\u91cf\r\ndrwx----- android_code\r\n-rwxrwxrw a.out\r\ndrwxr-xr- assembly\r\ndrwxr-xr- bin\r\ndrwx----- code<\/pre>\n<h4>-d\u548c-f\u9009\u9879<\/h4>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u7684\u4f8b\u5b50\u53ef\u4ee5\u770b\u5230\uff0c\u5982\u679c\u5355\u7eaf\u4f7f\u7528-c\u9009\u9879\uff0c\u5219\u5fc5\u987b\u5f88\u6e05\u695a\u6240\u8981\u89e3\u6790\u5b57\u7b26\u5728\u6bcf\u884c\u4e2d\u7684\u4f4d\u7f6e\uff1b\u53e6\u5916\uff0c-c\u9009\u9879\u9002\u7528\u4ece\u683c\u5f0f\u56fa\u5b9a\u7684\u6587\u4ef6\u6216\u547d\u4ee4\u8f93\u51fa\u4e2d\u89e3\u6790\u51fa\u6240\u9700\u8981\u7684\u5b57\u7b26\u3002\u5982\u679c\u6587\u4ef6\u6570\u636e\u7684\u7ec4\u7ec7\u683c\u5f0f\u4e0d\u56fa\u5b9a\uff0c\u5219\u5f88\u96be\u4f7f\u7528-c\u9009\u9879\u4ece\u6bcf\u884c\u4e2d\u90fd\u89e3\u6790\u51fa\u6240\u9700\u7684\u5b57\u7b26\u3002<\/p>\n<p>\u6bd4\u5982\u6211\u4eec\u5e38\u5e38\u4f1a\u9047\u5230\u8fd9\u6837\u7684\u4e2a\u4eba\u4fe1\u606f\uff0c\u5305\u542b\u59d3\u540d\uff0c\u6027\u522b\uff0c\u57ce\u5e02\uff0c\u7231\u597d\uff0c\u7535\u8bdd\uff1a<\/p>\n<pre class=\"brush:c\">edsionte:male:xian:music:18717375182\r\nzhyun:famle:beijing:basketball:18654737473\r\nliting:male:zhangjiajie:tableball:15784859345<\/pre>\n<p>\u73b0\u5728\u5982\u679c\u8981\u89e3\u6790\u51fa\u59d3\u540d\uff0c\u4f7f\u7528-c\u9009\u9879\u5219\u4e0d\u53ef\u80fd\u505a\u5230\u3002\u4e0d\u8fc7\u8be5\u6587\u4ef6\u6709\u4e00\u4e2a\u7279\u70b9\uff0c\u6bcf\u884c\u4fe1\u606f\u4e2d\u7684\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u4f7f\u7528\u5206\u53f7\u9694\u5f00\uff0c\u6b64\u65f6\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528-f\u548c-d\u9009\u9879\uff1a<\/p>\n<p><strong>cut -ddchar -ffields file<\/strong><\/p>\n<p>dchar\u8868\u793a\u6211\u4eec\u6790\u53d6\u5b57\u6bb5\u65f6\u6240\u4f9d\u636e\u7684\u5206\u9694\u7b26\uff1bfields\u6807\u793a\u6211\u4eec\u6240\u8981\u6790\u53d6\u7684\u5b57\u6bb5\u5e8f\u53f7\uff0c\u53ef\u7528\u9017\u53f7\u9694\u5f00\u591a\u4e2a\u5b57\u6bb5\u5e8f\u53f7\u3002\u5bf9\u4e8e\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u4e48\u505a\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-laptop:~\/shelltest$ cut -d: -f1 info\r\nedsionte\r\nzhyun\r\nliting<\/pre>\n<p>cut\u547d\u4ee4\u5c06\u5236\u8868\u7b26(\\t)\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u5b57\u6bb5\u5206\u9694\u7b26\uff0c\u5982\u679c\u67d0\u4e2a\u6587\u4ef6\u7528\u5236\u8868\u7b26\u4f5c\u4e3a\u6bcf\u884c\u5404\u4e2a\u5b57\u6bb5\u7684\u5206\u9694\u7b26\uff0c\u5219\u4f7f\u7528cut -ffield file\u5373\u53ef\u6790\u53d6\u76f8\u5e94\u5b57\u6bb5\u3002<\/p>\n<h4>paste\u547d\u4ee4<\/h4>\n<p>\u4e0ecut\u547d\u4ee4\u76f8\u53cd\uff0cpaste\u547d\u4ee4\u53ef\u4ee5\u5c06\u591a\u4e2a\u6587\u4ef6\u5bf9\u5e94\u884c\u7684\u6570\u636e\u8fde\u63a5\u5728\u4e00\u8d77\uff0c\u6570\u636e\u4e4b\u95f4\u4f7f\u7528\u5236\u8868\u7b26\u9694\u5f00\u3002\u5408\u5e76\u540e\u7684\u7ed3\u679c\u9ed8\u8ba4\u5728\u6807\u51c6\u8f93\u51fa\u4e2d\u8f93\u51fa\u3002\u8be5\u547d\u4ee4\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u4e3a\uff1a<\/p>\n<p><strong>paste files<\/strong><\/p>\n<p>\u6bd4\u5982\u5c06\u4e0b\u9762\u7684name\u548cgender\u5408\u5e76\u5728\u4e00\u8d77\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ cat name\r\nedsionte\r\nwangsen\r\nzhanyu\r\nedsionte@edsionte-desktop:~\/shelltest$ cat gender\r\nm\r\nm\r\nf\r\nf\r\nm\r\nedsionte@edsionte-desktop:~\/shelltest$ paste name gender\r\nedsionte\tm\r\nwangsen\tm\r\nzhanyu\tf\r\n\tf\r\n\tm<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u7531\u4e8ename\u6587\u4ef6\u4e2d\u53ea\u6709\u4e09\u884c\u6570\u636e\uff0c\u56e0\u6b64gender\u6587\u4ef6\u4e2d\u6700\u540e\u4e24\u884c\u548c\u7a7a\u5b57\u7b26\u5408\u5e76\u5728\u4e00\u8d77\u3002<\/p>\n<h4>-d\u9009\u9879<\/h4>\n<p>\u901a\u8fc7-d\u9009\u9879\u53ef\u4ee5\u6307\u5b9a\u4efb\u610f\u5206\u9694\u7b26\u6765\u9694\u5f00\u4e0d\u540c\u6587\u4ef6\u6bcf\u884c\u7684\u5185\u5bb9\uff0c\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u4e3a\uff1a<\/p>\n<p><strong>paste -dchars files<\/strong><\/p>\n<p>dchar\u53ef\u4ee5\u53d6\u591a\u4e2a\u5206\u9694\u7b26\uff0c\u6bcf\u4e2a\u5206\u9694\u7b26\u4f9d\u6b21\u9694\u5f00files\u4e2d\u6bcf\u4e2a\u6587\u4ef6\u6bcf\u884c\u7684\u6570\u636e\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ paste -d~, name gender number\r\nedsionte~m,123\r\nwangsen~m,456\r\nzhanyu~f,789\r\n~f,\r\n~m,<\/pre>\n<p>\u4ece\u8fd9\u4e2a\u4f8b\u5b50\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0cname\u548cnumber\u6587\u4ef6\u7684\u7b2c4\u548c\u7b2c5\u884c\u7684\u6570\u636e\u5747\u4e3a\u7a7a\u3002<\/p>\n<h4>-s\u9009\u9879<\/h4>\n<p>\u901a\u8fc7\u8fd9\u4e2a\u9009\u9879\u53ef\u4ee5\u5c06\u4e00\u4e2a\u6587\u4ef6\u6bcf\u884c\u7684\u6570\u636e\u90fd\u5408\u5e76\u5728\u4e00\u8d77\u3002\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ ls\r\nfile1  file3  file5  file7  gender  number\r\nfile2  file4  file6  file8  name\r\nedsionte@edsionte-desktop:~\/shelltest$ ls | paste -s -d@\r\nfile1@file2@file3@file4@file5@file6@file7@file8@gender@name@number<\/pre>\n<p>\u5bf9\u4e8e\u4e0a\u8ff0\u4e24\u4e2a\u547d\u4ee4\uff0c\u4f7f\u7528-d\u9009\u9879\u65f6\u6700\u597d\u5c06\u5206\u9694\u7b26\u653e\u5728\u5355\u5f15\u53f7\u4e2d\u3002\u539f\u56e0\u5f88\u7b80\u5355\uff0c\u6bd4\u5982\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ ls | paste -s -d;\r\npaste\uff1a\u9009\u9879\u9700\u8981\u4e00\u4e2a\u53c2\u6570 -- d\r\n\u8bf7\u5c1d\u8bd5\u6267\u884c\"paste --help\"\u6765\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/pre>\n<p>\u539f\u56e0\u662fshell\u5e76\u6ca1\u6709\u5c06;\u4f5c\u4e3a\u5206\u9694\u7b26\uff0c\u800c\u662f\u8ba4\u4e3a\u5b83\u662fpaste\u547d\u4ee4\u7684\u7ed3\u675f\u6807\u5fd7\u3002\u8fd9\u91cc\u7684\u539f\u56e0\u8ddf\u8f6c\u4e49\u5b57\u7b26\u5dee\u4e0d\u591a\uff0c\u56e0\u4e3a\u6b64\u65f6\u6211\u4eec\u9700\u8981\u4f7f\u7528;\u7684\u672c\u610f\u3002\u52a0\u4e0a\u5355\u5f15\u53f7\u5373\u53ef\u6210\u529f\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\uff1a<\/p>\n<pre class=\"brush:c\">edsionte@edsionte-desktop:~\/shelltest$ ls | paste -s -d';'\r\nfile1;file2;file3;file4;file5;file6;file7;file8;gender;name;number<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>cut\u547d\u4ee4 \u987e\u540d\u601d\u4e49\uff0ccut\u547d\u4ee4\u5c31\u662f\u4ece\u6587\u672c\u6587\u4ef6\u6216\u4ece\u67d0\u4e2a\u547d\u4ee4\u7684\u8f93\u51fa\u6570\u636e\u4e2d\u88c1\u526a\uff08\u6790\u53d6\uff09\u51fa\u60f3\u8981\u7684\u6570\u636e\u57df\u3002cut\u547d\u4ee4\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[153],"tags":[155,125],"class_list":["post-2297","post","type-post","status-publish","format-standard","hentry","category-shell","tag-shell","tag-linux"],"views":5926,"_links":{"self":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/2297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/comments?post=2297"}],"version-history":[{"count":0,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/posts\/2297\/revisions"}],"wp:attachment":[{"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/media?parent=2297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/categories?post=2297"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/edsionte.com\/techblog\/wp-json\/wp\/v2\/tags?post=2297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}