0

I am trying to replace some character strings using sed in batch console. My input consists in a file with lines like these:

$ 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__

Now I'm trying to erase the 'D_number__' string before the names with this sed command and it is not replacing anything:

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

Any idea of which is the problem? Thanks!

ALG
  • 181
  • 1
  • 11
  • see also [Why does my regular expression work in X but not in Y?](https://unix.stackexchange.com/questions/119905/why-does-my-regular-expression-work-in-x-but-not-in-y) – Sundeep Dec 18 '17 at 15:00

1 Answers1

2

Your regex syntax is perl like.

So if you want to keep it :

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

or with :

sed -r 's/D_[0-9]+__//g' qiimetax_sorted.txt > qiimesed.tx
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
  • 2
    suggestion: use `-E` instead of `-r`.. GNU sed supports both and as far as I know, some other sed versions are now supporting `-E`.. – Sundeep Dec 18 '17 at 14:59