{"id":468,"date":"2015-05-12T21:58:07","date_gmt":"2015-05-12T12:58:07","guid":{"rendered":"http:\/\/tajibook.com\/?p=468"},"modified":"2015-05-12T22:00:17","modified_gmt":"2015-05-12T13:00:17","slug":"replace-strings-in-multiple-files","status":"publish","type":"post","link":"https:\/\/blog.codebase.co.jp\/en\/replace-strings-in-multiple-files","title":{"rendered":"Replace Strings in Multiple Files"},"content":{"rendered":"<p>&#8220;sed&#8221; command can be used for replacing strings in a file. For example, you can use the command below to replace &#8220;Apple&#8221; with &#8220;Orange&#8221; in fruits.txt file.<\/p>\n<pre class=\"lang:sh decode:true\">$ sed -i\".bkp\" -e \"s\/Apple\/Orange\/g\" fruits.txt<\/pre>\n<p>Parameter &#8220;-i&#8221; makes\u00a0the target file\u00a0overwritten, but a backup is created by specifying a string (&#8220;.bkp&#8221; for this case) after &#8220;-i&#8221; whose filename has the string as suffix.<\/p>\n<p>You can combine &#8220;xargs&#8221; and &#8220;find&#8221; command with &#8220;sed&#8221; to process multiple files at once. &#8220;find&#8221; is for searching files and &#8220;xargs&#8221; is for executing any commands using values from standard input as parameters. For example, you can use the command below to replace &#8220;Apple&#8221; with &#8220;Orange&#8221; in all files in current directory.<\/p>\n<pre class=\"lang:sh decode:true\">$ find . -maxdepth 1 -type f | xargs sed -i\".bkp\" -e \"s\/Apple\/Orange\/g\"<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;sed&#8221; command can be used for replacing strings in a file. For example, you can use the command be (&hellip;) <a href=\"https:\/\/blog.codebase.co.jp\/en\/replace-strings-in-multiple-files\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"441","footnotes":""},"categories":[34],"tags":[],"class_list":["post-468","post","type-post","status-publish","format-standard","hentry","category-unix","en-US"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts\/468","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/comments?post=468"}],"version-history":[{"count":2,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts\/468\/revisions"}],"predecessor-version":[{"id":471,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/posts\/468\/revisions\/471"}],"wp:attachment":[{"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/media?parent=468"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/categories?post=468"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.codebase.co.jp\/wp-json\/wp\/v2\/tags?post=468"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}