Solved

How can I convert m/d/yyyy to YYYY-MM-DD in a CSV file?

Posted on 2011-02-25
6
643 Views
Last Modified: 2012-05-11
Hi EEs,
  I'm working on converting and cleansing a database dump from an older FileMaker Pro database to import into MySQL (for a web project) and need a nice tidy way to convert the date format of m/d/yyyy to YYYY-MM-DD.  I know perl, sed and awk should be able to do the trick, but what I've found so far hasn't worked (definitely a syntax problem).  It'd be great if your solution was a perl script that could be run as "date-fmt.pl FILENAME", but even a simple sed command would be appreciated.  I'm dealing with a database that has over 230,000 entries and using OpenOffice extensions to change the format takes wayyyyy too long.

0
Comment
Question by:digitaly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 

Author Comment

by:digitaly
ID: 34984274
While I'm at it, if you can add the process in this sed command to the script, too, that'd be excellent.  No sweat if you can't or don't though.



sed -e 's/\"//g' -e 's/\\//g' -e 's/^/\"/' -e 's/$/\"/' -e 's/\t/\"\,\"/g'
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34984515
perl script

while ( <> )
{
	# m/d/yyyy
	# YYYY-MM-DD
	while (/([0-9]+)\/([0-9]+)\/([0-9]+)/)
	{
	    $_ = $` . $3 . '-' . sprintf("%02d",$1) . '-' . sprintf("%02d",$2) . $';
	}

	print $_;
}

Open in new window

0
 
LVL 16

Accepted Solution

by:
sjklein42 earned 500 total points
ID: 34984604
Including your sed commands:

while ( <> )
{
	# m/d/yyyy
	# YYYY-MM-DD
	while (/([0-9]+)\/([0-9]+)\/([0-9]+)/)
	{
	    $_ = $` . $3 . '-' . sprintf("%02d",$1) . '-' . sprintf("%02d",$2) . $';
	}

	s/\"//g;
	s/\\//g;
	s/^/\"/;
	s/$/\"/;
	s/\t/\"\,\"/g;
	
	print $_;
}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:digitaly
ID: 34985214
Awesome!  Worked great!  Thanks a load!!! :-)
0
 

Author Closing Comment

by:digitaly
ID: 34985217
Excellent, accurate and FAST response.  THANK YOU!!!
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 34985248
thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question