I need to search for a file having a string and replace whole line with a new line only if it is not commented. Actual scenario is that I need to replace the include of a file with new file only if the include statement is not commented. Example
include("../mytest.php");
// include("../mytest.php");
expected result
require_once("mytestnew.php");
// include("../mytest.php");
I have tried some of the following sed commands found at different places on web:
sed -i '/^[\t]*\/\/.*/!/include.*mytest.php/c\require_once("mytestnew.php");' file.php
sed -i '/^[\t]*\/\/.*/!{include.*mytest.php/c\require_once("mytestnew.php");}' file.php
sed -i '/^[\t]*\/\/.*/b;include.*mytest.php/c\require_once("mytestnew.php");' file.php
sed -i '/^[\t]*\/\/.*/!s/include.*mytest.php/c\require_once("mytestnew.php");/g' file.php
In most of the other cases as well either I am getting unexpected { or s etc error or the result is not as expected.
Thanks in Advance!