如何使用bash文本处理命令将一个字符转换成两个字符的单词元素?

ygya80vv  于 2021-06-20  发布在  Mysql
关注(0)|答案(3)|浏览(322)

我在一个文件夹中有许多这样的脚本:

INSERT INTO fv_xml_binary_adim VALUES (1, '<FeatureVector><feature>project</feature><feature>w</feature><feature>focus</feature><feature>d</feature><feature>new</feature><feature>cut</feature><feature>tool</feature><feature>design</feature><feature>allow</feature><feature>increas</feature><feature>high</feature><feature>speed</feature><feature>machin</feature><feature>hsm</feature><feature>product</feature></FeatureVector>');

我想把一个字符的元素转换成两个字符的元素。我想把上面的命令转换成:

INSERT INTO fv_xml_binary_adim VALUES (1, '<FeatureVector><feature>project</feature><feature>w0</feature><feature>focus</feature><feature>d0</feature><feature>new</feature><feature>cut</feature><feature>tool</feature><feature>design</feature><feature>allow</feature><feature>increas</feature><feature>high</feature><feature>speed</feature><feature>machin</feature><feature>hsm</feature><feature>product</feature></FeatureVector>');

如何使用sed或其他bash文本处理命令实现它?

thtygnil

thtygnil1#

sed ```
$ sed -E 's/>(.)</>\10</g' file

bsxbgnwa

bsxbgnwa2#

sed 您可以使用:

sed 's/>\([a-z]\)</>\10</g'

这将改变 >w< 进入 >w0< 等等。

cgfeq70w

cgfeq70w3#

您可以尝试将regex与sed一起使用 sed -i -E "s%(feature>)([a-z]{1})(</feature)%\1\20\3%g" file

相关问题