{"id":320,"date":"2008-10-23T14:21:24","date_gmt":"2008-10-23T22:21:24","guid":{"rendered":"http:\/\/www.codebelay.com\/blog\/?p=320"},"modified":"2008-10-23T14:27:57","modified_gmt":"2008-10-23T22:27:57","slug":"remove-m-characters-and-more-with-replbash","status":"publish","type":"post","link":"https:\/\/www.codebelay.com\/blog\/2008\/10\/23\/remove-m-characters-and-more-with-replbash\/","title":{"rendered":"Remove ^M characters and more with repl.bash"},"content":{"rendered":"<p>Hey folks, this is a goody but quicky.<\/p>\n<p>First off, respect the character encoding of a file. I don&#8217;t know how many devs out there violate this rule, but if you&#8217;re like me and <a href=\"http:\/\/joelonsoftware.com\/articles\/Unicode.html\">Joel On Software<\/a>, you&#8217;ll agree that you should <b>respect the character encoding of a file<\/b>.<\/p>\n<p>If you happen to see that your file has gotten code page 1252 aka Windows-Latin 1 in it, then you&#8217;ll have a variety of random characters like ^M or ?~@~Y or ?~@~\\ or ?~@~] .<\/p>\n<p>Well, I wrote a script that removes these guys and makes sure that the file format of Unix is respected. Here it is:<\/p>\n<div style=\"background: #000; color: #fff; padding: 5px 5px 5px 5px;\">\n#!\/bin\/bash<br \/>\n#<br \/>\n# By: barce[a t]codebelay.com<br \/>\n# &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\n# this script replaces microsoft special chars with plain ol&#8217; ascii<br \/>\n#<br \/>\n# usage: .\/repl.bash filename<br \/>\n#<\/p>\n<p># replace ^M characters<br \/>\nperl -pi -e &#8216;s\/\\x{0D}\\x{0A}\/\\x{0A}\/g&#8217; $1<\/p>\n<p># replace garbage with single-quotes<br \/>\n# ?~@~Y<br \/>\nperl -pi -e &#8216;s\/\\x{E2}\\x{80}\\x{99}\/\\x{27}\/g&#8217; $1<br \/>\nperl -pi -e &#8216;s\/\\x{80}\\x{99}\/\\x{27}\/g&#8217; $1<br \/>\nperl -pi -e &#8216;s\/\\x{80}\\x{9c}\/\\x{27}\/g&#8217; $1<br \/>\nperl -pi -e &#8216;s\/\\x{80}\\x{9d}\/\\x{27}\/g&#8217; $1<\/p>\n<p># replace garbage with asterisk<br \/>\n# ?~@?<br \/>\n# e280 a2<br \/>\nperl -pi -e &#8216;s\/\\x{E2}\\x{80}\\x{A2}\/\\x{2A}\/g&#8217; $1<\/p>\n<p># replace garbage quotes with plain quotes<br \/>\n# start: ?~@~\\<br \/>\n# close: ?~@~]<br \/>\n# e2 809c<br \/>\nperl -pi -e &#8216;s\/\\x{E2}\\x{80}\\x{9C}\/\\x{22}\/g&#8217; $1<br \/>\nperl -pi -e &#8216;s\/\\x{E2}\\x{80}\\x{9D}\/\\x{22}\/g&#8217; $1<\/p>\n<p># replace garbage hyphens with plain hyphens<br \/>\nperl -pi -e &#8216;s\/\\x{E2}\\x{80}\\x{93}\/\\x{2D}\/g&#8217; $1<\/p>\n<p># replace garbage with ellipsis<br \/>\nperl -pi -e &#8216;s\/\\x{E2}\\x{80}\\x{A6}\/\\x{2E}\\x{2E}\\x{2E}\/g&#8217; $1\n<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hey folks, this is a goody but quicky. First off, respect the character encoding of a file. I don&#8217;t know how many devs out there violate this rule, but if you&#8217;re like me and Joel On Software, you&#8217;ll agree that you should respect the character encoding of a file. If you happen to see that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[170,4],"tags":[210,208,211,213,214,207,209,212],"class_list":["post-320","post","type-post","status-publish","format-standard","hentry","category-command-line","category-how-to","tag-ascii","tag-bash","tag-code-page-1252","tag-latin-1","tag-perl","tag-shell-scripting","tag-utf-8","tag-windows-latin-1"],"_links":{"self":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/comments?post=320"}],"version-history":[{"count":0,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/320\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/media?parent=320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/categories?post=320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/tags?post=320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}