{"id":415,"date":"2008-12-07T11:35:15","date_gmt":"2008-12-07T16:35:15","guid":{"rendered":"http:\/\/www.summet.com\/blog\/?p=415"},"modified":"2008-12-07T11:35:15","modified_gmt":"2008-12-07T16:35:15","slug":"global-search-and-replace-in-multiple-files","status":"publish","type":"post","link":"https:\/\/www.summet.com\/blog\/2008\/12\/07\/global-search-and-replace-in-multiple-files\/","title":{"rendered":"Global search and replace in multiple files"},"content":{"rendered":"<p>Searching and replacing a bit of text in a lot of files is a very common problem. Lots of tools exist to get it done. On unix systems, awk is one favorite, and I found <a href=\"http:\/\/www.packetnexus.com\/kb\/greyarts\/docs\/979617680:10293.html\">this webpage<\/a> with a simple search and replace example.<br \/>\nUnfortunately, I wanted to search for \\prob and replace it with %\\prob. The difficulty is that the backslash character is &#8220;special&#8221;, so you have to escape it with other backslashes. <\/p>\n<p>Here is my updated example command to run in each directory:<\/p>\n<p>awk &#8216;{gsub(\/\\\\prob\/,&#8221;%\\\\prob&#8221;, $0); print > FILENAME}&#8217; *.tex<\/p>\n<p>It does a global substitution for the regex \\\\prob with string %\\prob in the<br \/>\nwhole input file ($0) for every file that ends in .tex<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Searching and replacing a bit of text in a lot of files is a very common problem. Lots of tools exist to get it done. On unix systems, awk is one favorite, and I found this webpage with a simple &hellip; <a href=\"https:\/\/www.summet.com\/blog\/2008\/12\/07\/global-search-and-replace-in-multiple-files\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,3,12],"tags":[],"class_list":["post-415","post","type-post","status-publish","format-standard","hentry","category-commentary","category-linux","category-goodlinks"],"_links":{"self":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/posts\/415","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/comments?post=415"}],"version-history":[{"count":0,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/posts\/415\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/media?parent=415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/categories?post=415"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.summet.com\/blog\/wp-json\/wp\/v2\/tags?post=415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}