{"id":13772,"date":"2015-04-27T05:05:59","date_gmt":"2015-04-26T19:05:59","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=13772"},"modified":"2015-04-26T23:13:22","modified_gmt":"2015-04-26T13:13:22","slug":"linux-global-substitutions-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-global-substitutions-primer-tutorial\/","title":{"rendered":"Linux Global Substitutions Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/oscommerceksh.jpg\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Linux Global Substitutions Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Linux\/oscommerceksh.jpg\" title=\"Linux Global Substitutions Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">Linux Global Substitutions Primer Tutorial<\/p><\/div>\n<p>We&#8217;ve discussed the topic of Linux (or unix) shell scripting method of global file substitutions with the very old <a target=_blank title='Are you interested in combating drudgery?' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=262'>Are you interested in combating drudgery?<\/a> and the example usage in <a target=_blank title='str_replace.sh' href='http:\/\/www.rjmprogramming.com.au\/Learning\/str_replace.sh_GETME'>str_replace.sh<\/a><\/p>\n<p>Yesterday we revisited the idea regarding the upgrade to PHP 5.4 recently, and its affect on the osCommerce sample data website we have <a target=_blank title='osCommerce sample data website at RJM Programming' href='http:\/\/www.rjmprogramming.com.au\/oscommerce2\/catalog'>here<\/a> at the www.rjmprogramming.com.au domain.<\/p>\n<p>This <a target=_blank href='http:\/\/php.net\/manual\/en\/migration53.deprecated.php' title='PHP: Deprecated features in PHP 5.3.x - Manual'>PHP: Deprecated features in PHP 5.3.x &#8211; Manual<\/a> link outlines some of the issues we tackled using global substitution methods.<\/p>\n<p>So, with these deprecated features in mind we came up with the Korn Shell scripting code you could call <a target=_blank title='oscommerce.ksh' href='http:\/\/www.rjmprogramming.com.au\/Linux\/oscommerce.ksh_GETME'>oscommerce.ksh<\/a> as you can see below &#8230;<\/p>\n<p><code><br \/>\n#!\/bin\/ksh<br \/>\n# oscommerce.ksh<br \/>\n# Changes to osCommerce code to fix for PHP 5.4 ...<br \/>\n#  PHP: Deprecated features in PHP 5.3.x - Manual<br \/>\n#  http:\/\/php.net\/manual\/en\/migration53.deprecated.php<br \/>\nif [ ! -z \"$1\" ]; then<br \/>\n files=$(grep -rl HTTP_POST_VARS ${1}) && echo $files | xargs sed -i 's\/HTTP_POST_VARS\/_POST\/g'<br \/>\n files=$(grep -rl HTTP_COOKIE_VARS ${1}) && echo $files | xargs sed -i 's\/HTTP_COOKIE_VARS\/_COOKIE\/g'<br \/>\n files=$(grep -rl HTTP_GET_VARS ${1}) && echo $files | xargs sed -i 's\/HTTP_GET_VARS\/_POST\/g'<br \/>\n files=$(grep -rl HTTP_SERVER_VARS ${1}) && echo $files | xargs sed -i 's\/HTTP_SERVER_VARS\/_SERVER\/g'<br \/>\n files=$(grep -rl HTTP_ENV_VARS ${1}) && echo $files | xargs sed -i 's\/HTTP_ENV_VARS\/_ENV\/g'<br \/>\n files=$(grep -rl HTTP_SESSION_VARS ${1}) && echo $files | xargs sed -i 's\/HTTP_SESSION_VARS\/_SESSION\/g'<br \/>\n files=$(grep -rl HTTP_POST_FILES ${1}) && echo $files | xargs sed -i 's\/HTTP_POST_FILES\/_FILES\/g'<br \/>\n files=$(grep -rl HTTP_REQUEST_VARS ${1}) && echo $files | xargs sed -i 's\/HTTP_REQUEST_VARS\/_REQUEST\/g'<br \/>\nelse<br \/>\n echo \"Please add a path of interest\"<br \/>\nfi<br \/>\nexit<br \/>\n<\/code><\/p>\n<p> &#8230; and we also include a version that would work for Mac OS X environments that have an additional parameter for <i>sed<\/i> shown with <a target=_blank title='oscommerce_mac.ksh' href='http:\/\/www.rjmprogramming.com.au\/Linux\/oscommerce_mac.ksh_GETME'>oscommerce_mac.ksh<\/a><\/p>\n<p>Of great help with the ideas of this script was this <a target=_blank title='using grep and sed to find and replace a string' href='http:\/\/stackoverflow.com\/questions\/6178498\/using-grep-and-sed-to-find-and-replace-a-string'>link<\/a> &#8230; thanks.<\/p>\n<p>Below are links to information regarding some of the Linux commands used in the script &#8230;<\/p>\n<ul>\n<li><a target=_blank title='grep' href='http:\/\/www.computerhope.com\/unix\/ugrep.htm'>grep<\/a><\/li>\n<li><a target=_blank title='echo' href='http:\/\/www.computerhope.com\/unix\/uecho.htm'>echo<\/a><\/li>\n<li><a target=_blank title='xargs' href='http:\/\/www.computerhope.com\/unix\/xargs.htm'>xargs<\/a><\/li>\n<li><a target=_blank title='sed' href='http:\/\/www.computerhope.com\/unix\/used.htm'>sed<\/a><\/li>\n<\/ul>\n<p> &#8230; enjoy today&#8217;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Linux\/oscommerceksh.jpg\" title='Click picture'>tutorial<\/a>, and hope to see you again soon.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d13772' onclick='var dv=document.getElementById(\"d13772\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=Linux\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d13772' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve discussed the topic of Linux (or unix) shell scripting method of global file substitutions with the very old Are you interested in combating drudgery? and the example usage in str_replace.sh Yesterday we revisited the idea regarding the upgrade to &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/linux-global-substitutions-primer-tutorial\/\">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":[12,29,37],"tags":[544,677,707,725,933,997,1115,1139,1319,1472],"class_list":["post-13772","post","type-post","status-publish","format-standard","hentry","category-elearning","category-operating-system","category-tutorials","tag-grep","tag-korn-shell","tag-linux","tag-mac-os-x","tag-php-5-4","tag-programming","tag-sed","tag-shell-script","tag-tutorial","tag-xarg"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/13772"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=13772"}],"version-history":[{"count":1,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/13772\/revisions"}],"predecessor-version":[{"id":14530,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/13772\/revisions\/14530"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=13772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=13772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=13772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}