Replacing / by - in date

Dear Friends,

Following is manupulated output of our script.

e.g.

lkme_lpst 2
Pur_dt 31/12/2011
bl_dt   01/02/2011
rt_dt   02/02/2011
prod_btch 19/1452147-5210

We further want to manupulate it and want to replace / by -

i.e.

Lkme_lpst 2
Pur_dt 31-12-2011
bl_dt   01-02-2011
rt_dt   02-02-2011
prod_btch 19/1452147-5210

at the same time we dont want to convert / to - where its not a date (like in earlier example product_batch)

Please guide us to do the same.
Thanks
Anushree

How about this?

perl -nle 's#(\d{2})/(\d{2})/(\d{4})#$1-$2-$3#g;print;'  inputfile

OR

sed 's#\(.*\)/\(.*\)/\(.*\)#\1-\2-\3#g' inputfile

Dear Pravin,

tried 1st solution and it worked without any changes.

Thanks a lot for quick reply.
Take care

Anu.

awk '{gsub(/\//,"-",$2)}1' infile

Hey Friends,
Sorry forgot to mention one imp thing

Now as suggested I am using

perl -nle 's#(\d{2})/(\d{2})/(\d{4})#$1-$2-$3#g;print;' INPUTFILE

to get desired output.

But I forgot to mention that I want to convert Date format from MM-DD-YYYY to DD-MM-YYYY.

Please guide.

Anu.

Change the captured group. like below.

 perl -nle 's#(\d{2})/(\d{2})/(\d{4})#$2-$1-$3#g;print;' inputfile

Wow Pravin, it worked.
Thanks a tonnn...
God bless you.

Anushree.

Hi Anushree,
The below sed will also work.

sed 's/\/\(..\)\//\-\1\-/p' <file_name>