I have looked through many posts here and elsewhere on this subject, but none of the solutions offered seem to work for me. I need to replace a string (which contains buggy nonsensical PHP code) with another string (containing the correct PHP code) in all files within a particular folder. I understand that the only characters that need escaping when using sed are ampersands, backslashes, and whichever character is used as the delimiter.
The string I want to search for is:
$arguments = func_get_args();$numargs = func_num_args();for($i=1; $i < $numargs; $i++){$arguments[$i] = $arguments = func_get_args();$arguments[$i];} The string I want to replace it with is:
$arguments = func_get_args();$numargs = func_num_args();for($i=1; $i < $numargs; $i++){$arguments[$i] = &$arguments[$i];} I have tried numerous variations but cannot get it to work. I think the following command should work (but doesn't).
find /folder/to/search -name Function.php -type f -exec sed -i 's|$arguments = func_get_args();$numargs = func_num_args();for($i=1; $i < $numargs; $i++){$arguments[$i] = $arguments = func_get_args();$arguments[$i];}|$arguments = func_get_args();$numargs = func_num_args();for($i=1; $i < $numargs; $i++){$arguments[$i] = \&$arguments[$i];}|' {} \; This is driving me insane - any assitance would be greatly appreciated!