Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何在bash中替换多行正则表达式并将其存储在变量中?_Regex_Bash_Shell_Command Line - Fatal编程技术网

Regex 如何在bash中替换多行正则表达式并将其存储在变量中?

Regex 如何在bash中替换多行正则表达式并将其存储在变量中?,regex,bash,shell,command-line,Regex,Bash,Shell,Command Line,我想在bash脚本中使用regex进行多行替换,并将该值存储在变量中。以下操作不起作用: 我得到的结果是: 第1行新的\u值 第2行替换我 所以只有第一行被替换了。如何为此设置标志(全局、多行)或使用diff-regex方式?添加另一个斜杠使其成为全局搜索: str="line 1 replace_me line 2 replace_me" echo "${str//replace_me/new_value}" 输出: 第1行新值 第2行新值 str="line 1 replace_me

我想在bash脚本中使用regex进行多行替换,并将该值存储在变量中。以下操作不起作用:

我得到的结果是:

第1行新的\u值
第2行替换我


所以只有第一行被替换了。如何为此设置标志(全局、多行)或使用diff-regex方式?

添加另一个斜杠使其成为全局搜索:

str="line 1 replace_me
line 2 replace_me"

echo "${str//replace_me/new_value}"
输出:

第1行新值
第2行新值
str="line 1 replace_me
line 2 replace_me"

echo "${str//replace_me/new_value}"