{"id":423,"date":"2024-01-18T13:56:54","date_gmt":"2024-01-18T05:56:54","guid":{"rendered":"https:\/\/blog.quantoyo.com\/?p=423"},"modified":"2024-01-18T14:36:38","modified_gmt":"2024-01-18T06:36:38","slug":"tail-%e8%88%87-sed-%e7%b5%84%e5%90%88%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/blog.quantoyo.com\/?p=423","title":{"rendered":"tail \u8207 sed \u7d44\u5408\u4f7f\u7528"},"content":{"rendered":"\n<p>\u5982\u4f55\u5c07\u67d0\u500b\u6a94\u6848\u65b0\u589e\u7684\u90e8\u5206\uff0c\u53e6\u5916\u5b58\u4e0b\u4f86<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>tail -f -n 0 source.log |sed -u &gt; new.txt\n\ntail -f \u53ef\u4ee5\u986f\u793a\u51fasource.log \u5f9e\u76ee\u524d\u958b\u59cb\u65b0\u589e\u7684\u90e8\u5206\n-n 0 \u5c31\u53ea\u6703\u628a\u591a\u51fa\u4f86\u7684\u90e8\u5206\u986f\u793a\u51fa\u4f86\uff0c\u4e0d\u52a0\u9019\u6bb5\u7684\u8a71\uff0c\u6703\u5c07\u6700\u5f8c\u5e7e\u884c\u90fd\u79c0\u51fa\u4f86\n\n| \u53ef\u4ee5\u5c07\u6240\u5f97\u5230\u7684\u6587\u5b57\u50b3\u5f80\u4e0b\u4e00\u5c64(\u547c\u53ebsed \u8655\u7406)\n\nsed \u53d6\u5f97\u5f8c\uff0c-u \u70ba\u7121\u7de9\u885d\u6a21\u5f0f\uff0c\u4e5f\u5c31\u662f\u6703\u76f4\u63a5\u8f38\u51fa\n&gt; \u53ef\u4ee5\u5c07\u8f38\u51fa\u5c0e\u5165\u5230 new.txt\u6587\u4ef6\u4e2d<\/code><\/pre>\n\n\n\n<p>\u53e6\u5916tail \u4e5f\u53ef\u4ee5\u642d\u914d gerp \u904e\u6ffe\u51fa\u95dc\u9375\u8cc7\u8a0a\u4f86\u53e6\u5916\u5132\u5b58<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>tail -f -n 0 source.log |grep 'keyword' |sed -u &gt; new.txt\n\n\u5c31\u53ea\u6703\u5c07\u8a72\u884c\u6709\u5beb\u5230keyword \u7684\u5f80\u5f8c\u9001\uff0c\u4e26\u8a18\u9304\u4e0b\u4f86<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1174\" height=\"1234\" src=\"https:\/\/blog.quantoyo.com\/wp-content\/uploads\/2024\/01\/image-12.png\" alt=\"\" class=\"wp-image-425\" srcset=\"https:\/\/blog.quantoyo.com\/wp-content\/uploads\/2024\/01\/image-12.png 1174w, https:\/\/blog.quantoyo.com\/wp-content\/uploads\/2024\/01\/image-12-285x300.png 285w, https:\/\/blog.quantoyo.com\/wp-content\/uploads\/2024\/01\/image-12-143x150.png 143w, https:\/\/blog.quantoyo.com\/wp-content\/uploads\/2024\/01\/image-12-768x807.png 768w\" sizes=\"auto, (max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px\" \/><\/figure>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u62ff\u4f86\u57f7\u884c\u53d6\u4ee3<\/p>\n\n\n\n<pre class=\"wp-block-code has-cyan-bluish-gray-background-color has-background has-small-font-size\"><code>tail -f -n 0 source.log |grep --line-buffered 'keyword' |sed -u -e $'s\/keyword\/replacedword\/' > new.txt\n\n\u9019\u500b\u4f5c\u6cd5\u662f\u53ef\u4ee5\u627e\u5230keyword \u4e26\u4f7f\u7528 sed \u53d6\u4ee3\u5f8c\u4e26\u8f38\u51fa\n\n--line-buffered \u9019\u500b\u662fgrep \u7684\u9078\u9805\uff0c\u8207sed \u7684 -u \u529f\u80fd\u985e\u4f3c\uff0c\u53ef\u4ee5\u4e00\u8d77\u4f7f\u7528!\n\n\u6240\u4ee5\uff0c\u5982\u679c sed -u \u6709\u7570\u5e38\uff0c\u53ef\u4ee5\ntail -f -n 0 source.log |grep --line-buffered 'keyword' |sed  > new.txt\n\u4e5f\u6709\u4e00\u6a23\u7684\u6548\u679c<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5c07\u67d0\u500b\u6a94\u6848\u65b0\u589e\u7684\u90e8\u5206\uff0c\u53e6\u5916\u5b58\u4e0b\u4f86<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[37,30,39,69],"class_list":["post-423","post","type-post","status-publish","format-standard","hentry","category-technology","tag-linux","tag-macos","tag-sed","tag-tail"],"_links":{"self":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=423"}],"version-history":[{"count":6,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/423\/revisions"}],"predecessor-version":[{"id":431,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=\/wp\/v2\/posts\/423\/revisions\/431"}],"wp:attachment":[{"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.quantoyo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}