[英]Modify sed command to catch substrings
I have the example text: 我有示例文本:
"are "insulin sensitizers" "
I am trying to use the below command to find and replace the xml quote command with a single quote but it only works for the first one and the second that follows "sensitizers" is left unchanged. 我正在尝试使用以下命令来查找xml quote命令并将其替换为单引号,但它仅适用于第一个,而紧随“敏化剂”的第二个则保持不变。
command: 命令:
grep -rl """ ./ | xargs sed -i "s/"/'/"
result: 结果:
"are 'insulin sensitizers" "
desired result: 预期结果:
"are 'insulin sensitizers' "
You will need to use g
flag in sed
for global substitution: 您将需要在
sed
使用g
标志进行全局替换:
grep -Zirl """ . | xargs -0 sed -i "s/"/'/g"
Also note use of -Z
option in grep
and -0
in xargs
to take care of files with special characters and whitespaces. 还要注意在
grep
使用-Z
选项,在xargs
中使用-0
来处理带有特殊字符和空格的文件。
As per man grep
: 根据
man grep
:
-Z
,--null
-Z
,----null
Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name.
输出零字节(ASCII NUL字符),而不是通常在文件名后的字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.