sed 通配符搜索替换 [英] sed wildcard search replace
问题描述
我在 Centos、bash 上使用 sed.
I'm using sed on Centos, bash.
我想用下面一行文本中的空格替换 \plain 和 }} 之间的所有内容:
I want to replace everything between \plain and }} with a space in the below line of text:
stuff here \plain \f2\fs20\cf2 4:21-23}} more stuff over here, could be anything.
\plain 和 }} 之间的文本会有所不同(不同的数字/数字).我如何做一个通配符来包含 \plain 和 }} 之间的所有内容.
The text between \plain and }} will vary (different numbers/numbers). How can I do a wildcard to include everything between \plain and }}.
我希望一个简单的 * 可以获取两者之间的所有内容,但是 shell 中的通配符似乎不是这样工作的:
I was hoping a simple * would grab everything between the two but the wildcard in shell doesn't seem to work like this:
s/\\plain *}}/ /g;
答案可能是结合了这一点?[a-zA-Z0-9.] 但这不包括文本中的反斜杠、冒号和破折号.
The answer may be something incorporating this? [a-zA-Z0-9.] but that doesn't account for the backslashes, colons, and dashes in the text.
推荐答案
只需在 * 前添加点即可匹配所有内容.
Just add dot before * to match everything.
即s/\\plain .*}}//g
应该可以工作.
这篇关于sed 通配符搜索替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!