[英]Using sed with find to insert file content
How can I add something ex: 我如何添加一些东西:
idea before </svg> in all svg files ?
find -name "*.svg" -exec sed -i s/"</svg>"/"idea</svg>"/g {} \;
It doesn't work also with 它也不适用于
find -name "*.svg" -exec sed -i s|"</svg>"|"idea</svg>"/g {} \;
Your embedded slashes are causing sed confusion: 您的嵌入式斜线引起sed混乱:
sed -i s/"</svg>"/"idea</svg>"/g ##wrong##
Pick a delimiter that will NOT causing problems. 选择一个不会引起问题的定界符。 Put the whole thing in quotes. 将整个内容用引号引起来。
sed -i "s=</svg>=idea</svg>=g"
sed
is a line editor and sed -i.old
takes an input file to modify in place and save a copy to a .old
file. sed
是行编辑器,而sed -i.old
使用输入文件进行修改,并将副本保存到.old
文件。 We have to match </svg>
and replace it with 'idea' and put the matched part back ( \\1
) 我们必须匹配</svg>
并将其替换为'idea',然后将匹配的部分放回( \\1
)
sed -i.old 's/\(\<\/svg\>\)/idea\1/g' *.svg
(Notice we don't need find for this, giving *.svg
to sed
should suffice.) (注意,我们不需要为此查找,将*.svg
赋予sed
就足够了。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.