{"id":59,"date":"2008-12-22T18:23:49","date_gmt":"2008-12-22T18:23:49","guid":{"rendered":"http:\/\/dev001.dl\/yan\/wdp\/?p=59"},"modified":"2026-01-20T05:06:49","modified_gmt":"2026-01-20T05:06:49","slug":"awk","status":"publish","type":"post","link":"http:\/\/www.lalife.net\/?p=59","title":{"rendered":"awk &#038; Sed"},"content":{"rendered":"<p>Calculate sum of the file size<\/p>\n<p>ls -l access_log.2008-12-20*|gawk &#8216;{a+=$5;} END {print a;}&#8217;<\/p>\n<p>\u00a0<\/p>\n<p>Edit special lines using regular expression<\/p>\n<p>awk &#8216;\/aaa\/ &#8216; filename<\/p>\n<p>\u00a0<\/p>\n<p>Change file names using sed<\/p>\n<p>##Example: from\u00a0access_log.2008-12-20.01.gz.1 \u00a0to\u00a0access_log.2008-12-20.01.1.gz<\/p>\n<p>for file in `ls access_log.2008-12-20.*`<\/p>\n<p>do<\/p>\n<p>newname=`echo $file|sed &#8216;s\/\\(access_log.2008-12-20.[0-9][0-9]\\).gz.\\([0-9]*\\)\/\\1.\\2.gz\/&#8217;`<\/p>\n<p>size=`ls -l $file|awk &#8216;{print $5}&#8217;`<\/p>\n<p>if [ $size -gt 100 ];then<\/p>\n<p>\u00a0\u00a0echo &#8220;$file-&gt; $newname&#8221;<\/p>\n<p>fi<\/p>\n<p>mv -v $file $newname<\/p>\n<p>done<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Calculate sum of the file size ls -l access_log.2008-12-20*|gawk &#8216;{a+=$5;} END {print a;}&#8217; \u00a0 Edit special lines using regular expression awk &#8216;\/aaa\/ &#8216; filename \u00a0 Change file names using sed ##Example: from\u00a0access_log.2008-12-20.01.gz.1 \u00a0to\u00a0access_log.2008-12-20.01.1.gz for file in `ls access_log.2008-12-20.*` do newname=`echo &hellip; <a href=\"http:\/\/www.lalife.net\/?p=59\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-shell"],"_links":{"self":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=59"}],"version-history":[{"count":1,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":1969,"href":"http:\/\/www.lalife.net\/index.php?rest_route=\/wp\/v2\/posts\/59\/revisions\/1969"}],"wp:attachment":[{"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lalife.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}