如何使用多行模式在 bash 中进行字符串替换?
为了说明,我提供了一个伪代码:
TARGET_STR=' $N = "magic_quotes_gpc = <b>"._("On")."</b>";
$D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case.");
$S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'.");
$R = ini_get('magic_quotes_gpc');
$M = TRUE;
$this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );'
REPLACE_STR=' /* NOTE: "Magic_quotes_gpc" is no longer required. We taught GOsa2 to deal with it (see /usr/share/gosa/html/main.php). By Questor */
/* Automatic quoting must be turned on */
/* $D = _("Increase your server security by setting magic_quotes_gpc to 'on'. PHP will escape all quotes in strings in this case.");
$S = _("Search for 'magic_quotes_gpc' in your php.ini and set it to 'On'.");
$R = ini_get('magic_quotes_gpc');
$M = TRUE;
$this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M ); */'
PATH_TO_FILE='/usr/share/gosa/setup/class_setupStep_Checks.inc'
some_command '$TARGET_STR/$REPLACE_STR' $PATH_TO_FILE
注意 I:我想使用 bash 变量。
注二:我想使用没有转义的字符串(TARGET_STR 和 REPLACE_STR 中的字符串)。
谢谢!
您可以将所有相关的文本字符串转换为十六进制字符串,以十六进制执行替换,然后将结果转换回文本。这可能是这样的:
这将为您提供的测试数据产生所需的结果。