简体   繁体   English

sed regex 替换多次出现

[英]sed regex to replace multiple occurrences

The following sed expression is meant to operate on LaTeX source code and replace citet with citep :以下 sed 表达式旨在对 LaTeX 源代码进行操作并将citet替换为citep

sed -i -e 's/\\citet/\\citep/'

However, it seems that if citet appears twice in a row但是,似乎如果citet出现两次

\citet{bichot2011graph} \citet{DBLP:journals/corr/BulucMSSS13}

it replaces only the first occurrence and turns it into:它仅替换第一次出现并将其转换为:

\citep{bichot2011graph} \citet{DBLP:journals/corr/BulucMSSS13}

Where is the mistake?错误在哪里?

You need to use the global flag g :您需要使用全局标志g

sed -i -e 's/\\citet/\\citep/g'

See this reference for more detail.有关更多详细信息,请参阅参考资料。

g - Apply the replacement to all matches to the regexp, not just the first. g - 将替换应用于正则表达式的所有匹配项,而不仅仅是第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM