如果行有引号,则sed命令失败 [英] sed command fails if line has quote
问题描述
我正在尝试创建一个脚本来搜索文件列表并删除
以下行
< meta http-equiv = QUOT;内容类型"含量=" text / html的; charset =<?php echo
CHARSET; ?>">
我这样做是通过生成一个sed命令并使用系统执行
就像这样:
$ t = sprintf("%s \" s /< meta http-equiv =" Content-Type" content =" text / html;
charset =<?php echo CHARSET;?>">%s / g \"%s>%s",$ sedPath,$ str1_rpl,
$ infile,$ outfile);
system($ t);
问题是要替换的文本中的引号。 sed认为它是b / b
作为其命令的一部分而忽略了它之后的一切。例如,如果我使用
< meta http-equiv =" Content-Type" content =
搜索字符串,它有效。但是,如果我使用
< meta http-equiv =" Content-Type" content ="
它不起作用。我试过逃避报价(\)但是没有帮助。
有没有人对我还能尝试什么有任何建议?
t = sprintf("%s \" s /< meta http-equiv =" Content-Type" content =" text / html ;
charset =<?php echo CHARSET;?>">%s / g \"%s>%s",
< blockquote> sedPath,
str1_rpl,
I''m trying to make a script that will search a list of files and remove
the following line
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo
CHARSET; ?>">
I''m doing this by generating a sed command and using system to execute
it like so:
$t = sprintf("%s \"s/<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo CHARSET; ?>">%s/g\" %s >%s", $sedPath,$str1_rpl,
$infile, $outfile);
system($t);
The problem is the quote found in the text to be replaced. sed sees it
as part of its command and ignores everything after it. For example, if
I use
<meta http-equiv="Content-Type" content=
for the search string, it works. But if I use
<meta http-equiv="Content-Type" content="
it doesn''t work. I have tried escaping the quote (\")but that didn''t help.
Does anyone have any suggestions as to what else I could try?
t = sprintf("%s \"s/<meta http-equiv="Content-Type" content="text/html;
charset=<?php echo CHARSET; ?>">%s/g\" %s >%s",
sedPath,
str1_rpl,
这篇关于如果行有引号,则sed命令失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!