我想在多个文件中用null替换<lexicon uri="file://C:/image/png/grammars/custom/image-custom.lex?SWI.type=backup"/><lexicon uri="file://C:/image/jpg/grammars/custom/image-dot-custom.lex?SWI.type=backup"/>。
代码如下所示。
sed -i s|<lexicon uri="file://C:/image/png/grammars/custom/image-custom.lex?SWI.type=backup"/><lexicon uri="file://C:/image/jpg/grammars/custom/image-dot-custom.lex?SWI.type=backup"/>||g *这里我得到了一个错误:
< was unexpected at this time.请为我澄清什么在这里不起作用。
发布于 2018-07-24 05:32:49
请你试着跟我说一下,如果这对你有帮助的话,请告诉我。通过使用#作为sed的分隔符,您不需要在其中转义/,它只需要转义.,?就不具有特殊意义。
sed -E 's#<lexicon uri="file://C:/image/png/grammars/custom/image-custom\.lex\?SWI\.type=backup"/><lexicon uri="file://C:/image/jpg/grammars/custom/image-dot-custom\.lex\?SWI\.type=backup"/>##' Input_file对其进行了以下测试:
sed --version
GNU sed version 4.2.1发布于 2018-07-24 14:50:48
与#一起工作
sed -i -e 's#<lexicon uri="file://C:/image/png/grammars/custom/image-custom.lex?SWI.type=backup"/><lexicon uri="file://C:/image/jpg/grammars/custom/image-dot-custom.lex?SWI.type=backup"/>##g' test.txt
发布于 2018-07-24 15:43:24
该模式包含shell元字符,需要引用或转义。通常,在Bash中,您应该在字符串周围使用单引号,除非您需要shell来插值变量和命令替换并解释反斜杠序列(在这种情况下使用双引号),或者执行空白标记化和通配符展开(在这种情况下不使用引号)。另见When to wrap quotes around a shell variable?
sed -i 's|<lexicon uri="file://C:/image/png/grammars/custom/image-custom.lex?SWI.type=backup"/><lexicon uri="file://C:/image/jpg/grammars/custom/image-dot-custom.lex?SWI.type=backup"/>||' *我还取出了g标志,只有当您期望在一行中有多个匹配时,这才有意义。(也许你还是这么做的,在这种情况下,很明显是把它放回去了。)
https://stackoverflow.com/questions/51491024
复制相似问题