如何从文本中删除特定的乳胶命令及其后面的右括号,但将文本保留在括号/内
请随意填写建议 SED、AWK、Perl 或任何可以完成这项工作的内容
输入无感示例:
We \edit{Introduce a} model for analyzing \emph{data} from various
experimental designs, \edit{such as 23 paired or longitudinal}.
输出:
We Introduce a model for analyzing \emph{data} from various
experimental designs, such as 23 paired or longitudinal.
附言。我在我的 tex 文件中引入了很多小的编辑。我希望突出显示这些编辑,以便我的合作者可以看到它们。但之后我想用一两个命令删除所有突出显示。
答案1
$ cat file
We \edit{introduce a} model for analyzing data from various
experimental designs, \edit{such as paired or longitudinal}.
$ sed 's/\(\\edit{\)\([a-z ]*\)\(}\)/\2/g' file
We introduce a model for analyzing data from various
experimental designs, such as paired or longitudinal.
如果您的文件如下所示:
$ cat file
We \edit{Introduce a} model for analyzing \emph{data} from various
experimental designs, \edit{such as 23 paired or longitudinal}.
那么你应该尝试:
sed 's/\(\\[a-z]*{\)\([A-Za-z0-9 ]*\)\(}\)/\2/g' file
We Introduce a model for analyzing data from various
experimental designs, such as 23 paired or longitudinal.
如果你想保留\emph{data}
然后使用:
$ sed 's/\(\\edit{\)\([A-Za-z0-9 ]*\)\(}\)/\2/g' file
We Introduce a model for analyzing \emph{data} from various
experimental designs, such as 23 paired or longitudinal.
或者更流畅的方式:
$ sed 's/\\edit{\([^}]*\)}/\1/g' file