正则表达式在sed命令中无法正确匹配[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我试图在批处理控制台中使用sed替换一些字符串。我的输入包含一个文件,其中包含以下行:

$ head qiimetax_sorted.txt

A61579.1.1437 
D_0__Bacteria;D_1__Thermotogae;D_2__Thermotogae;D_3__Thermotogales;
D_4__Fervidobacteriaceae;D_5__Fervidobacterium;Ambiguous_taxa;D_7__;
D_8__;D_9__;D_10__;D_11__;D_12__;D_13__;D_14__
AAAA02020712.626.2096   
D_0__Bacteria;D_1__Proteobacteria;D_2__Alphaproteobacteria;D_3__Rhizobiales;
D_4__Bradyrhizobiaceae;D_5__uncultured;D_6__Oryza sativa 
Indica Group (long-grained rice);D_7__;D_8__;D_9__;D_10__;D_11__;D_12__;
D_13__;D_14__

现在我试图在使用此sed命令的名称之前删除'D_number__'字符串并且它不替换任何内容:

sed -r 's/D_\d+__//g' qiimetax_sorted.txt > qiimesed.txt

知道哪个是问题?谢谢!

regex bash unix sed
1个回答
2
投票

你的正则表达式语法是perl。

所以,如果你想保留它:

perl -pe 's/D_\d+__//g' qiimetax_sorted.txt > qiimesed.tx

或与

sed -r 's/D_[0-9]+__//g' qiimetax_sorted.txt > qiimesed.tx
© www.soinside.com 2019 - 2024. All rights reserved.