Hopefully an Easy Question

I have a file name in this format

ABC_WIRE_TRANS_YYYYMMDD_00.DAT

I need to cut out the _00 out of the file name everytime. It could be _00, _01,_02, etc ....

How do I cut it out to look as follows?

ABC_WIRE_TRANS_YYYYMMDD.DAT

A possible solution :

$ echo ABC_WIRE_TRANS_YYYYMMDD_00.DAT | sed 's/_[0-9][0-9]\././'
ABC_WIRE_TRANS_YYYYMMDD.DAT
$

Jean-Pierre.

The letters YYYYMMDD are actually going to be a date 20070531. So that will not work.

Actually aigles solution would work. To make it look better.

echo ABC_WIRE_TRANS_YYYYMMDD_00.DAT | sed 's/_..\.DAT/.DAT/g'

A little bit more secure:

echo ABC_WIRE_TRANS_YYYYMMDD_00.DAT | sed 's/__[0-9][0-9]\.DAT$/.DAT/g'

Jean-Pierre.

just one way, assuming extension .DAT or other 3 letter extension

#string="ABC_WIRE_TRANS_YYYYMMDD_00.DAT"
#echo ${string%_*DAT}${string:(-4)}
ABC_WIRE_TRANS_YYYYMMDD.DAT

thanks for your help