Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.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
String 如果存在特定子字符串,是否替换字符串?_String_Macos_Shell - Fatal编程技术网

String 如果存在特定子字符串,是否替换字符串?

String 如果存在特定子字符串,是否替换字符串?,string,macos,shell,String,Macos,Shell,我想替换一个字符串,当且仅当该行中存在一个字符串时。这应该跨文件夹中的所有文件执行 1. This is My String. 2. Get This string as input. 在上述两个字符串中,如果存在“字符串”,请将My替换为您的 类似的输出应该是 1. This is your String. 2. Get This string as input. 或 输出甚至应该反映在文件中。我想更改文件夹中的所有文件。请使用sed-I选项或检查awk是否有同步替换。 sed '/Str

我想替换一个字符串,当且仅当该行中存在一个字符串时。这应该跨文件夹中的所有文件执行

1. This is My String.
2. Get This string as input.
在上述两个字符串中,如果存在“字符串”,请将
My
替换为
您的

类似的输出应该是

1. This is your String.
2. Get This string as input.


输出甚至应该反映在文件中。我想更改文件夹中的所有文件。请使用
sed-I
选项或检查
awk
是否有同步替换。
sed '/String/ s/My/YOUR/g' input
awk '/String/{gsub(/My/,"YOUR")}1' input