{"id":3793,"date":"2020-11-24T18:32:10","date_gmt":"2020-11-24T09:32:10","guid":{"rendered":"https:\/\/www.chihayafuru.jp\/tech\/?p=3793"},"modified":"2021-10-20T17:33:32","modified_gmt":"2021-10-20T08:33:32","slug":"%e7%89%b9%e5%ae%9a%e3%81%ae%e6%96%87%e5%ad%97%e3%82%a8%e3%83%b3%e3%82%b3%e3%83%bc%e3%83%87%e3%82%a3%e3%83%b3%e3%82%b0%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ae%e6%a4%9c%e7%b4%a2","status":"publish","type":"post","link":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/archives\/3793","title":{"rendered":"\u6587\u5b57\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u306b\u3088\u308b\u30d5\u30a1\u30a4\u30eb\u691c\u7d22"},"content":{"rendered":"<p>\u30b5\u30d6\u30d5\u30a9\u30eb\u30c0\u4ee5\u4e0b\u306b\u3042\u308b <code>*.c<\/code> \u30d5\u30a1\u30a4\u30eb\u306e\u306a\u304b\u304b\u3089\u3001\u7279\u5b9a\u306e\u6587\u5b57\u30b3\u30fc\u30c9(UTF-8)\u3067\u3042\u308b\u3082\u306e\u3092\u30ea\u30b9\u30c8\u30a2\u30c3\u30d7\u3059\u308b\u3002<\/p>\n<pre class=\"lang:default highlight:0 decode:true \" >$ find . -name '*.c' -type f -print0 | xargs -0 nkf --guess | grep 'UTF-8'<\/pre>\n<p><!--more--><\/p>\n<p>&nbsp;<\/p>\n<h3>nkf &#8211;guess \u306e\u51fa\u529b\u4f8b<\/h3>\n<pre class=\"lang:default highlight:0 decode:true \" >.\/driver\/foo.c: Shift_JIS (CRLF)\r\n.\/driver\/bar.c: CP932 (CRLF)\r\n.\/mod\/fiz.c: UTF-8 (LF)<\/pre>\n<p>&nbsp;<\/p>\n<h3>1. find<\/h3>\n<ul>\n<li><code>.<\/code> : \u30ab\u30ec\u30f3\u30c8\u30d5\u30a9\u30eb\u30c0\u304b\u3089\u518d\u5e30\u7684\u306b\u691c\u7d22\u3059\u308b\u3002\n<li><code>-name '*.c'<\/code> : \u62e1\u5f35\u5b50\u304c c \u306e\u30d5\u30a1\u30a4\u30eb\u3092\u691c\u7d22\u3059\u308b\u3002<\/li>\n<li><code>-type f<\/code> : \u691c\u7d22\u5bfe\u8c61\u3092\u30d5\u30a1\u30a4\u30eb\u3068\u3059\u308b\u3002\uff08\u30d5\u30a9\u30eb\u30c0\u3092\u9664\u304f\uff09<\/li>\n<li><code>-print0<\/code> : \u6587\u5b57\u5217\u533a\u5207\u308a\u3092NUL\u6587\u5b57\u3068\u3059\u308b\u3002\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u6539\u884c\u6587\u5b57\uff09<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>2. xargs<\/h3>\n<ul>\n<li><code>-0<\/code> : \u6587\u5b57\u5217\u533a\u5207\u308a\u3092NUL\u6587\u5b57\u3068\u3059\u308b\u3002\uff08\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u6539\u884c\u6587\u5b57\uff09<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>3. nkf<\/h3>\n<ul>\n<li><code>-guess<\/code> : \u6587\u5b57\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3092\u5224\u5b9a\uff08\u63a8\u6e2c\uff09\u3059\u308b\u3002\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>4. grep<\/h3>\n<ul>\n<li><code>&#39;UTF-8&#39;<\/code> : \u691c\u7d22\u5bfe\u8c61\u306e\u6587\u5b57\u5217\u3092 &#39;UTF-8&#39; \u3068\u3059\u308b\u3002\n<\/ul>\n<p>&nbsp;<\/p>\n<hr>\n<p>&nbsp;<\/p>\n<pre class=\"lang:default highlight:0 decode:true \" >$ find . -name '*.c' -type f -exec nkf --guess {} + | grep 'UTF-8'<\/pre>\n<h3>-exec<\/h3>\n<ul>\n<li>\u691c\u7d22\u3067\u30de\u30c3\u30c1\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u540d\u3067 &quot;<code>nkf --guess<\/code>&quot; \u3092\u5b9f\u884c\u3059\u308b\u3002<\/li>\n<li><code>{}<\/code> \u304c\u30d1\u30b9\u540d\u306b\u7f6e\u304d\u63db\u3048\u3089\u308c\u308b\u3002<\/li>\n<li>\n    <code>+<\/code> &nbsp; \u30b0\u30eb\u30fc\u30d7\u5b9f\u884c\u3002\u53ef\u80fd\u306a\u9650\u308a\u591a\u304f\u306e\u8907\u6570\u306e\u30d1\u30b9\u540d\u3067nkf\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002<br \/>\n    &nbsp; &nbsp; &nbsp; \u3010\u4f8b\u3011 <code>nkf --guess foo.c bar.c fiz.c<\/code>\n  <\/li>\n<li>\n    <code>\\;<\/code> &nbsp; \u5358\u4f53\u5b9f\u884c\u3002\u30d1\u30b9\u540d\u6bce\u306b\u4e00\u3064\u4e00\u3064nkf\u30b3\u30de\u30f3\u30c9\u3092\u5b9f\u884c\u3059\u308b\u3002<br \/>\n    &nbsp; &nbsp; &nbsp; \u3010\u4f8b\u3011 <code>nkf --guess foo.c; nkf --guess bar.c; nkf --guess fiz.c<\/code>\n  <\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3>\u95a2\u9023\u30ea\u30f3\u30af<\/h3>\n<ul>\n<li><a href=\"\/tech\/index.php\/archives\/4758\">find\u30b3\u30de\u30f3\u30c9 -exec \u30aa\u30d7\u30b7\u30e7\u30f3<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u30b5\u30d6\u30d5\u30a9\u30eb\u30c0\u4ee5\u4e0b\u306b\u3042\u308b *.c \u30d5\u30a1\u30a4\u30eb\u306e\u306a\u304b\u304b\u3089\u3001\u7279\u5b9a\u306e\u6587\u5b57\u30b3\u30fc\u30c9(UTF-8)\u3067\u3042\u308b\u3082\u306e\u3092\u30ea\u30b9\u30c8\u30a2\u30c3\u30d7\u3059\u308b\u3002 $ find . -name &#8216;*.c&#8217; -type f -print0 | xargs -0 nkf &#8211; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-3793","post","type-post","status-publish","format-standard","hentry","category-memo"],"_links":{"self":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/3793","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/comments?post=3793"}],"version-history":[{"count":15,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/3793\/revisions"}],"predecessor-version":[{"id":4806,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/posts\/3793\/revisions\/4806"}],"wp:attachment":[{"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/media?parent=3793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/categories?post=3793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chihayafuru.jp\/tech\/index.php\/wp-json\/wp\/v2\/tags?post=3793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}