我有一个txt
看起来像这样的文件:
<sss>ss<
或者
<firstword>anotherword<
我希望它看起来像这样
<sss>ss</sss>
或者
<firstword>anotherword</firstword>
基本上采用第一个单词并将其放置在结束标记中。
在您问我尝试过什么之前,答案无济于事,我想不起。
有输入:
<abc>def<
<firstword>anotherword</firstword>
<ghi>klm<
使用:
sed 's/<\([^>]*\)>\(.*\)<$/<\1>\2<\/\1>/' input
输出:
<abc>def</abc>
<firstword>anotherword</firstword>
<ghi>klm</ghi>
sed行仅影响以结尾的行<
(因为<$
),并捕获第一<>
对之间以及'> <'之间的模式,并将所有内容粘贴回去,并在末尾复制第一对(加上结束符'>')
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句