用sed包装标记语句

用sed包装标记语句,sed,Sed,正文: \item青少年的进一步过程\uline{成熟和突触问题},以确定与正常发育功能偏离相关的基因和回路发育因素,以及可能特别针对干预的前驱阶段的点 目标:将段落中的\uline{text…}替换为{\color{cname}\uline{text…} 代码: 但是,得到如下输出: \item青少年{\color{cname}\uline{成熟和突触问题}的进一步过程,以确定与偏离正常发育功能相关的基因和回路发育因子,以及可能特别针对干预的前驱期点 任何帮助都将不胜感激 sed 's#\\

正文:

\item青少年的进一步过程\uline{成熟和突触问题},以确定与正常发育功能偏离相关的基因和回路发育因素,以及可能特别针对干预的前驱阶段的点

目标:将段落中的
\uline{text…}
替换为
{\color{cname}\uline{text…}

代码:

但是,得到如下输出:

\item青少年{\color{cname}\uline{成熟和突触问题}的进一步过程,以确定与偏离正常发育功能相关的基因和回路发育因子,以及可能特别针对干预的前驱期点

任何帮助都将不胜感激

sed  's#\\uline{[^}]*}#{\\color{cname}&}#g' file
如果需要,添加行范围或
-i

使用文本进行测试:

kent$  cat f
\item Further course of adolescent \uline{maturation and synaptic questions} 
\uline{points in prodromal stages where intervention} foo

kent$  sed  's#\\uline{[^}]*}#{\\color{cname}&}#g' f
\item Further course of adolescent {\color{cname}\uline{maturation and synaptic questions}} 
{\color{cname}\uline{points in prodromal stages where intervention}} foo
如果需要,添加行范围或
-i

使用文本进行测试:

kent$  cat f
\item Further course of adolescent \uline{maturation and synaptic questions} 
\uline{points in prodromal stages where intervention} foo

kent$  sed  's#\\uline{[^}]*}#{\\color{cname}&}#g' f
\item Further course of adolescent {\color{cname}\uline{maturation and synaptic questions}} 
{\color{cname}\uline{points in prodromal stages where intervention}} foo

虽然,当前用于临床诊断的
\uline{\textbf{not}仍然存在问题}foo。
@user3069585 yes,该行假定没有嵌套的
{}
s。但是,当前用于临床诊断的
\uline{\textbf{not}仍然存在问题}foo。
@user3069585 yes,该行假定没有嵌套的
{}
s。