sed 通配符搜索替换
我在 Centos 上使用 sed,bash。
我想用下面一行文本中的空格替换 \plain 和 }} 之间的所有内容:
stuff here \plain \f2\fs20\cf2 4:21-23}} more stuff over here, could be anything.
\plain 和 }} 之间的文本会有所不同(不同的数字/数字)。如何使用通配符来包含 \plain 和 }} 之间的所有内容。
我希望一个简单的 * 能够抓住两者之间的所有内容,但是 shell 中的通配符似乎并不像这样工作:
s/\\plain *}}/ /g;
答案可能是合并这个的东西? [a-zA-Z0-9.] 但这并没有考虑到文本中的反斜杠、冒号和破折号。
I'm using sed on Centos, bash.
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.
The text between \plain and }} will vary (different numbers/numbers). How can I do a wildcard to include everything between \plain and }}.
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;
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在 * 之前添加点即可匹配所有内容。
即
s/\\plain .*}}/ /g
应该可以。Just add dot before * to match everything.
i.e.
s/\\plain .*}}/ /g
should work.以下正则表达式 ...
... 将匹配以
\plain
开头、中间有任何内容、以}}
结尾的行。如果这没有用,请使用
^
(否定)来匹配除}}
之外的所有内容,而不是使用.*
来匹配所有内容。The following regex ...
... will match lines beginning with
\plain
, having anything in the middle, and ending with}}
.If that's no use, instead of
.*
to match everything, use^
(negation) to match everything that's not}}
.