{"id":961,"date":"2017-10-29T08:34:55","date_gmt":"2017-10-29T08:34:55","guid":{"rendered":"https:\/\/peloo.net\/?p=961"},"modified":"2017-11-05T06:05:07","modified_gmt":"2017-11-05T06:05:07","slug":"linux%e4%b8%ad%e8%bd%ac%e6%8d%a2%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%a4%a7%e5%b0%8f%e5%86%99%e7%9a%84%e5%a7%bf%e5%8a%bf","status":"publish","type":"post","link":"https:\/\/peloo.net\/?p=961","title":{"rendered":"Linux\u4e2d\u8f6c\u6362\u5b57\u7b26\u4e32\u5927\u5c0f\u5199\u7684\u59ff\u52bf"},"content":{"rendered":"<p>\n\t\u5728\u6570\u636e\u5904\u7406\u4e2d\u80af\u5b9a\u4f1a\u9047\u5230\u5927\u5c0f\u5199\u7684\u8f6c\u6362\uff0c\u4e0b\u9762\u8bf4\u8bf4Linux\u4e2d\u8f6c\u6362\u5b57\u7b26\u4e32\u5927\u5c0f\u5199\u7684\u51e0\u79cd\u65b9\u5f0f\u3002\n<\/p>\n<p>\n\t1&nbsp; AWK\n<\/p>\n<p>\n\tawk\u662f\u5f3a\u5927\u7684\u62a5\u544a\u751f\u6210\u5668\uff0c\u5176\u5f88\u591a\u5185\u7f6e\u51fd\u6570\u5f88\u6709\u7528\uff0c\u6bd4\u5982tolower\u548ctoupper\u5c31\u662f\u5904\u7406\u5927\u5c0f\u5199\u7684\uff0c\u7528\u547d\u4ee4\u8bf4\u8bdd\uff0c\u5982\u4e0b\uff0c\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/awk-toupper.png\" \/>\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/awk-tolower-1.png\" \/>\n<\/p>\n<p>\n\tPS\uff1agawk\u624d\u652f\u6301\u5927\u5c0f\u5199\u7684\u8f6c\u6362\u51fd\u6570tolower\u548ctoupper\u3002\n<\/p>\n<p>\n\t2&nbsp; tr\n<\/p>\n<p>\n\ttr\u662f\u4e13\u95e8\u5904\u7406\u5b57\u7b26\u4e32\u7684\u795e\u5668\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u5982\u4e0b\u56fe\uff0c\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/tr-tolower.png\" \/>\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/tr-toupper.png\" \/>\n<\/p>\n<p>\n\t3 tr\n<\/p>\n<p>\n\ttr\u547d\u4ee4\u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\u8f6c\u6362\u5927\u5c0f\u5199\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/tr-tolower-02.png\" \/>\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/tr-toupper-02.png\" \/>\n<\/p>\n<p>\n\t3&nbsp; sed\n<\/p>\n<p>\n\tsed\u4f5c\u4e3a\u53e4\u8001\u7684\u6d41\u7f16\u8f91\u5668\uff0c\u4ecd\u7136\u662f\u4e00\u628a\u6587\u672c\u5904\u7406\u7684\u5229\u5251\u3002\n<\/p>\n<p>\n\t\u5c06\u6bcf\u4e2a\u5355\u8bcd\u7684\u9996\u5b57\u6bcd\u53d8\u4e3a\u5927\u5199\uff0c\u5982\u56fe\uff0c\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/sed-toupper-01.png\" \/>\n<\/p>\n<p>\n\t\u5c06\u6240\u6709\u5c0f\u5199\u8f6c\u6362\u4e3a\u5927\u5199\uff0c\u5982\u56fe\uff0c\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/sed-toupper-02.png\" \/>\n<\/p>\n<p>\n\t\u5c06\u6240\u6709\u5927\u5199\u8f6c\u6362\u4e3a\u5c0f\u5199\uff0c\u5982\u56fe\uff0c\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"\" src=\"https:\/\/peloo.net\/wp-content\/uploads\/2017\/10\/sed-tolower.png\" \/>\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t\u5173\u4e8esed\u7684\u8fd9\u4e2a\u7528\u6cd5\u6211\u8fd8\u662f\u5934\u4e00\u6b21\u770b\u89c1\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u5728shell\u4e0b\u8fd0\u884cinfo sed\u67e5\u770b\u89e3\u91ca\uff0c\u5927\u81f4\u5982\u4e0b\uff0c\n<\/p>\n<p>\n\t&nbsp;\n<\/p>\n<p>\n\t3.5 The `s&#039; Command<br \/>\n\t===================\n<\/p>\n<p>\n\tThe syntax of the `s&#039; (as in substitute) command is<br \/>\n\t`s\/REGEXP\/REPLACEMENT\/FLAGS&#039;.&nbsp; The `\/&#039; characters may be uniformly<br \/>\n\treplaced by any other single character within any given `s&#039; command.<br \/>\n\tThe `\/&#039; character (or whatever other character is used in its stead)<br \/>\n\tcan appear in the REGEXP or REPLACEMENT only if it is preceded by a `\\&#039;<br \/>\n\tcharacter.\n<\/p>\n<p>\n\t&nbsp;&nbsp; The `s&#039; command is probably the most important in `sed&#039; and has a<br \/>\n\tlot of different options.&nbsp; Its basic concept is simple: the `s&#039; command<br \/>\n\tattempts to match the pattern space against the supplied REGEXP; if the<br \/>\n\tmatch is successful, then that portion of the pattern space which was<br \/>\n\tmatched is replaced with REPLACEMENT.\n<\/p>\n<p>\n\t&nbsp;&nbsp; The REPLACEMENT can contain `\\N&#039; (N being a number from 1 to 9,<br \/>\n\tinclusive) references, which refer to the portion of the match which is<br \/>\n\tcontained between the Nth `\\(&#039; and its matching `\\)&#039;.&nbsp; Also, the<br \/>\n\tREPLACEMENT can contain unescaped `&amp;&#039; characters which reference the<br \/>\n\twhole matched portion of the pattern space.&nbsp; Finally, as a GNU `sed&#039;<br \/>\n\textension, you can include a special sequence made of a backslash and<br \/>\n\tone of the letters `L&#039;, `l&#039;, `U&#039;, `u&#039;, or `E&#039;.&nbsp; The meaning is as<br \/>\n\tfollows:\n<\/p>\n<p>\n\t`\\L&#039;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp; Turn the replacement to lowercase until a `\\U&#039; or `\\E&#039; is found,\n<\/p>\n<p>\n\t`\\l&#039;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp; Turn the next character to lowercase,\n<\/p>\n<p>\n\t`\\U&#039;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp; Turn the replacement to uppercase until a `\\L&#039; or `\\E&#039; is found,\n<\/p>\n<p>\n\t`\\u&#039;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp; Turn the next character to uppercase,\n<\/p>\n<p>\n\t`\\E&#039;<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp; Stop case conversion started by `\\L&#039; or `\\U&#039;.\n<\/p>\n<p>\n\t&nbsp;&nbsp; To include a literal `\\&#039;, `&amp;&#039;, or newline in the final replacement,<br \/>\n\tbe sure to precede the desired `\\&#039;, `&amp;&#039;, or newline in the REPLACEMENT<br \/>\n\twith a `\\&#039;.\n<\/p>\n<p>\n\t&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u6570\u636e\u5904\u7406\u4e2d\u80af\u5b9a\u4f1a\u9047\u5230\u5927\u5c0f\u5199\u7684\u8f6c\u6362\uff0c\u4e0b\u9762\u8bf4\u8bf4Linux\u4e2d\u8f6c\u6362\u5b57\u7b26\u4e32\u5927\u5c0f\u5199\u7684\u51e0\u79cd\u65b9\u5f0f\u3002 1&nbsp; AWK awk\u662f\u5f3a\u5927\u7684\u62a5\u544a\u751f\u6210\u5668\uff0c\u5176\u5f88\u591a\u5185\u7f6e\u51fd\u6570\u5f88\u6709\u7528\uff0c\u6bd4\u5982tolower\u548ctoupper\u5c31\u662f\u5904\u7406\u5927\u5c0f\u5199\u7684\uff0c\u7528\u547d\u4ee4\u8bf4\u8bdd\uff0c\u5982\u4e0b\uff0c PS\uff1agawk\u624d\u652f\u6301\u5927\u5c0f\u5199\u7684\u8f6c\u6362\u51fd\u6570tolower\u548ctoupper\u3002 2&nbsp; tr tr\u662f\u4e13\u95e8\u5904\u7406\u5b57\u7b26\u4e32\u7684\u795e\u5668\uff0c\u8bdd\u4e0d\u591a\u8bf4\uff0c\u5982\u4e0b\u56fe\uff0c 3 tr tr\u547d\u4ee4\u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\u8f6c\u6362\u5927\u5c0f\u5199\u3002 3&nbsp; sed sed\u4f5c\u4e3a\u53e4\u8001\u7684\u6d41\u7f16\u8f91\u5668\uff0c\u4ecd\u7136\u662f\u4e00\u628a\u6587\u672c\u5904\u7406\u7684\u5229\u5251\u3002 \u5c06\u6bcf\u4e2a\u5355\u8bcd\u7684\u9996\u5b57\u6bcd\u53d8\u4e3a\u5927\u5199\uff0c\u5982\u56fe\uff0c \u5c06\u6240\u6709\u5c0f\u5199\u8f6c\u6362\u4e3a\u5927\u5199\uff0c\u5982\u56fe\uff0c \u5c06\u6240\u6709\u5927\u5199\u8f6c\u6362\u4e3a\u5c0f\u5199\uff0c\u5982\u56fe\uff0c &nbsp; \u5173\u4e8esed\u7684\u8fd9\u4e2a\u7528\u6cd5\u6211\u8fd8\u662f\u5934\u4e00\u6b21\u770b\u89c1\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u5728shell\u4e0b\u8fd0\u884cinfo sed\u67e5\u770b\u89e3\u91ca\uff0c\u5927\u81f4\u5982\u4e0b\uff0c &nbsp; 3.5 The `s&#039; Command =================== The syntax of the `s&#039; (as in substitute) command is `s\/REGEXP\/REPLACEMENT\/FLAGS&#039;.&nbsp; The `\/&#039; characters may be uniformly replaced by any other single character within any given `s&#039; command. The&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-961","post","type-post","status-publish","format-standard","hentry","category-linux-shell"],"aioseo_notices":[],"brizy_media":[],"_links":{"self":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=961"}],"version-history":[{"count":6,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/961\/revisions"}],"predecessor-version":[{"id":995,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/961\/revisions\/995"}],"wp:attachment":[{"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}