开发者

sed wildcard search replace

开发者 https://www.devze.com 2023-03-02 13:07 出处:网络
I\'m using sed on Centos, bash. I want to replace everything between \\plain and }} with a space in the below line of text:

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}} mo开发者_运维百科re 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.


Just add dot before * to match everything.

i.e. s/\\plain .*}}/ /g should work.


The following regex ...

^\\plain .*}}$

... 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 }}.

0

精彩评论

暂无评论...
验证码 换一张
取 消