我有一个包含以下行的LaTeX
文件:foo.tex
\includegraphics[width=0.49\textwidth]{img1}
\includegraphics{img2}
\subfloat{\includegraphics[width=0.3\textwidth]{img3}}
\subfloat{\includegraphics{img4}}
我想替换文件中的这些行以添加文件扩展名,如下所示:
\includegraphics[width=0.49\textwidth]{img1.png}
\includegraphics{img2.png}
\subfloat{\includegraphics[width=0.3\textwidth]{img3.png}}
\subfloat{\includegraphics{img4.png}}
我开始尝试使用sed
此命令:
cat foo.tex | sed 's/\(includegraphics.*[a-z,0-9,\-]}\)/\1.png}/g' > bar.tex
但它返回:
\includegraphics[width=0.49\textwidth]{img1}.png
\includegraphics{img2}.png
\subfloat{\includegraphics[width=0.3\textwidth]{img3}.png}
\subfloat{\includegraphics{img4}.png}
如何修复我的sed
命令以添加文件扩展名?
编辑
图像文件名不仅是 img1、img2 等。