Removing only Prefix string (!)

Hello everyone,

I want to remove only prefix ME_ from all the values that are present in the FILEA. Below code I'm using for this.

sed 's/ME\_//g' FILEA > FILEB

Using the above code, all ME_ values are getting removed from the file. But the problem here is I want to remove only Prefix ME_ , but the above code removing all ME_ wherever it's present in the string in file.

Example:

Input - 
ME_ABC_X,ME_DME_X, ME_FCX_X

Output-
ABC_X,DX,FCX_X

But the desired output is:
ABC_X, DME_X, FCX_X

Please advise.

Thanks in advance!

Try using EREs (extended regexes):

sed -r 's/(^|,| )ME\_/\1/g' file3
ABC_X,DME_X, FCX_X
1 Like

Note sed -r is GNU sed. With it, you could also do this:

sed 's/\<ME_//g' file
1 Like
perl -pe 's/\bME_//g' FILEA > FILEB
1 Like

Thanks RudiC, Scrutinizer and MadeInGermany!
All are worked the way I wanted.

Thanks again!!