{"id":2765,"date":"2016-07-14T17:17:38","date_gmt":"2016-07-14T09:17:38","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2765"},"modified":"2016-07-14T17:17:38","modified_gmt":"2016-07-14T09:17:38","slug":"%e5%9c%a8sed%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%a4%96%e9%83%a8%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2765.html","title":{"rendered":"\u5728sed\u4e2d\u4f7f\u7528\u5916\u90e8\u53d8\u91cf"},"content":{"rendered":"<p>=Start=<\/p>\n<h5>\u7f18\u7531\uff1a<\/h5>\n<p>\u5728\u7f16\u5199\u4e00\u4e2aBash\u811a\u672c\u65f6\u9700\u8981\u7528sed\u547d\u4ee4\u5bf9\u7ed3\u679c\u8fdb\u884c\u7cbe\u7b80\uff08\u5c06\u67d0\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7ecf\u5e38\u51fa\u73b0\u7684\u516c\u5171\u5b50\u4e32\u7528\u4e00\u4e2a\u77ed\u53d8\u91cf\u540d\u8868\u793a\uff09\uff0c\u6700\u521d\u7684\u5199\u6cd5\u662f\uff1a<\/p>\n<pre class=\"lang:default decode:true \">find \"${base_path}\" -maxdepth 1 -type f -iname \"*.py*\" 2&gt;\/dev\/null | xargs | tr ' ' ';' | sed -e 's#${base_path}#\\${base_path}#g'<\/pre>\n<p>\u4f46\u662f\u6ca1\u6709\u8d77\u5230\u4f5c\u7528\uff0c\u5f53\u65f6\u4e5f\u6bd4\u8f83\u5fd9\uff0c\u6ca1\u6709\u4ed4\u7ec6\u68c0\u67e5\u95ee\u9898\u51fa\u5728\u54ea\u4e86\uff0c\u53ea\u662f\u5148\u7b80\u5355\u7684\u628a\u6700\u540e\u7684sed\u66ff\u6362\u547d\u4ee4\u7ed9\u53bb\u6389\u4e86\u3002\u73b0\u5728\u521a\u597d\u6709\u70b9\u65f6\u95f4\uff0c\u627e\u5230\u4e86\u89e3\u51b3\u529e\u6cd5\uff0c\u5728\u6b64\u8bb0\u5f55\u4e00\u4e0b\uff0c\u65b9\u4fbf\u4ee5\u540e\u53c2\u8003\u3002<\/p>\n<h5>\u6b63\u6587\uff1a<\/h5>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<p>linux bash sed search with var<\/p>\n<h6>\u53c2\u8003\u89e3\u7b54\uff1a<\/h6>\n<p>\u4e09\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li><strong><span style=\"color: #ff0000;\">\u4f7f\u7528\u300c\u53cc\u5f15\u53f7\u300d\u800c\u4e0d\u662f\u300c\u5355\u5f15\u53f7\u300d<\/span><\/strong>\uff1b<\/li>\n<li><span style=\"color: #0000ff;\">\u4f7f\u7528\u591a\u91cd\u300c\u5355\u5f15\u53f7\u300d<\/span>\uff1b<\/li>\n<li>\u4f7f\u7528Bash\u5185\u7f6e\u7684\u5b57\u7b26\u4e32\u66ff\u6362\u64cd\u4f5c(\u6548\u7387\u6700\u9ad8)\u3002<\/li>\n<\/ol>\n<p>\u6d4b\u8bd5\u7528\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:default decode:true \">#!\/bin\/bash\n\nbase_path=\"\/root\/port_scan\"\necho $base_path\n\npy_files=\"\/root\/port_scan\/py_get_new_port_list2.py.2016-05-19 \/root\/port_scan\/py_get_new_port_list2.py.2016-05-17\"\necho $py_files\n# echo $py_files | sed -e 's#${base_path}#\\${base_path}#g'\necho $py_files | sed -e \"s#${base_path}#\\${base_path}#g\"    #work\necho $py_files | sed -e 's#'${base_path}'#\\${base_path}#g'  #work\necho $py_files | sed -e 's#\"${base_path}\"#\\${base_path}#g'\necho $py_files | sed -e 's#\/root\/port_scan#\\${base_path}#g'\necho ${py_files\/\/$base_path\/\\$base_path}                    #ok\necho ${py_files\/\/$base_path\/\\${base_path\\}}                 #work<\/pre>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/www.linuxquestions.org\/questions\/linux-software-2\/sed-with-bash-variables-304260\/\" target=\"_blank\">http:\/\/www.linuxquestions.org\/questions\/linux-software-2\/sed-with-bash-variables-304260\/<\/a><\/li>\n<li><a href=\"http:\/\/askubuntu.com\/questions\/76808\/how-do-i-use-variables-in-a-sed-command\">http:\/\/askubuntu.com\/questions\/76808\/how-do-i-use-variables-in-a-sed-command<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/11146098\/bash-use-a-variable-in-a-sed-command\">http:\/\/stackoverflow.com\/questions\/11146098\/bash-use-a-variable-in-a-sed-command<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/37566463\/linux-bash-sed-command-with-variable\">http:\/\/stackoverflow.com\/questions\/37566463\/linux-bash-sed-command-with-variable<\/a><\/li>\n<li><a href=\"http:\/\/www.tldp.org\/LDP\/abs\/html\/parameter-substitution.html\">http:\/\/www.tldp.org\/LDP\/abs\/html\/parameter-substitution.html<\/a><\/li>\n<li><a href=\"http:\/\/ixyzero.com\/blog\/archives\/512.html\" target=\"_blank\">Linux SHELL\u811a\u672c\u7684\u5b57\u7b26\u4e32\u622a\u53d6\u7b49\u64cd\u4f5c<\/a><\/li>\n<\/ul>\n<h5>\u53e6\uff1a<\/h5>\n<p>\u4e4b\u524d\u5728\u4f7f\u7528awk\u7684\u65f6\u5019\u4e5f\u9047\u5230\u8fc7\u4e00\u4e2a\u7c7b\u4f3c\u7684\u95ee\u9898\uff1a\u5728awk\u4e2d\u4f7f\u7528\u5916\u90e8\u53d8\u91cf\u3002\u5728\u6b64\u4e5f\u987a\u4fbf\u8bb0\u5f55\u4e00\u4e0b\uff1a<strong><span style=\"color: #ff0000;\">\u5982\u679c\u9700\u8981\u5728awk\u4e2d\u4f7f\u7528\u5916\u90e8\u7684\u53d8\u91cf\uff0c\u53ef\u4ee5\u501f\u52a9awk\u7684\u300c-v\u300d\u9009\u9879\u3002<\/span><\/strong><\/p>\n<h6>\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/13458804\/external-variable-in-awk\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/13458804\/external-variable-in-awk<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/19075671\/how-to-use-shell-variables-in-awk-script\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/19075671\/how-to-use-shell-variables-in-awk-script<\/a><\/li>\n<li><a href=\"http:\/\/unix.stackexchange.com\/questions\/56128\/external-variable-in-awk\" target=\"_blank\">http:\/\/unix.stackexchange.com\/questions\/56128\/external-variable-in-awk<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u5728\u7f16\u5199\u4e00\u4e2aBash\u811a\u672c\u65f6\u9700\u8981\u7528sed\u547d\u4ee4\u5bf9\u7ed3\u679c\u8fdb\u884c\u7cbe\u7b80\uff08\u5c06\u67d0\u4e2a\u5b57\u7b26\u4e32\u4e2d\u7ecf\u5e38\u51fa\u73b0\u7684\u516c\u5171\u5b50 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,11,7,12],"tags":[74,83,78,65],"class_list":["post-2765","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-linux","category-programing","category-tools","tag-awk","tag-bash","tag-sed","tag-shell"],"views":4938,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2765"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2765\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}