convert all date stamps in a file using shell or perl from 02/03/2011 to 02/03/2011 format

libertyforall2
libertyforall2 used Ask the Experts™
on
I want to convert all date stamps in a file using shell or perl from 02/03/2011 to 02/03/2011 format. This will modify the file not create a separate output file.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
You need to clarify your question as you've used the same date format.

Are you wanting to convert

DD/MM/YYYY to MM/DD/YYYY?

Author

Commented:
sorry meant 02/03/2011 to 02-03-2011 mm/dd/yyyy to mm-dd-yyyy
Top Expert 2007
Commented:

perl -i -pe 's#(\d\d)/(\d\d)/(\d{4})#$1-$2-$3#g' file

Open in new window

Author

Commented:
Is this for unix/linux? and how would I do it for all FILES in a directory ? *txt ?

Author

Commented:
Works great!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial