Advertisement

04.24.2008 at 07:23AM PDT, ID: 23350355
[x]
Attachment Details

Regex: swap date format and save file

Asked by tomcorcoran in Groovy, Java Programming Language, Regular Expressions

I have an ascii file of the form:

04/05/2008|00:00|17|8|0|1395|243|641|1|0|21|0|14998|0|0|0|0|0|0|0|0|0|0|0|1800|4|0|0|
04/05/2008|00:00|22|15|0|764|0|238|0|0|0|0|14998|0|0|0|0|0|0|0|0|0|0|0|1801|4|86|0|
04/05/2008|00:00|20|13|0|1487|98|149|1341|0|52|0|14993|0|0|0|0|0|0|0|0|0|0|36|1800|4|125|4|

The dates (04/05/2008) don't necessarily always occur at the start and can occur multiple times in each line -  there can be a lot of lines.

I want to read this file in, change the date format to yyyy/mm/dd and resave the file.
               String dateRegEx = '([0-9]{2})/([0-9]{2})/([0-9]{4})'
              def myFile = new File(myfile.txt)
              def matcher = (myFile.text =~ dateRegEx)

Now I have been having trouble with the replace...I'm thinking of something like:

        myFile.text.eachMatch(dateRegEx) {
                    def year = matcher[numMatch][3] // println "year = $matcher[0][3]" does not work
                    def month = matcher[numMatch][1]
                    def day = matcher[numMatch][2]
                    String newDate = "$year/$month/$day"
                    //println newDate
                    numMatch++
// no replace, how can do this with replaceAll?
//                    myFile.text.replace(dateRegEx,newDate)
          }      

Any advice appreciated,

Thanks, Tom.Start Free Trial
[+][-]04.25.2008 at 03:14AM PDT, ID: 21438085

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 03:58AM PDT, ID: 21438244

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 07:25AM PDT, ID: 21439875

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Groovy, Java Programming Language, Regular Expressions
Sign Up Now!
Solution Provided By: CEHJ
Participating Experts: 4
Solution Grade: A
 
 
[+][-]04.25.2008 at 07:37AM PDT, ID: 21439977

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 08:13AM PDT, ID: 21440335

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 08:19AM PDT, ID: 21440429

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 09:10AM PDT, ID: 21440905

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.25.2008 at 09:54AM PDT, ID: 21441276

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.26.2008 at 05:15AM PDT, ID: 21445302

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 01:02PM PDT, ID: 21450223

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 01:04PM PDT, ID: 21450232

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 02:49PM PDT, ID: 21450502

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 02:54PM PDT, ID: 21450519

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 04:06AM PDT, ID: 21452874

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 09:05AM PDT, ID: 21455238

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 05:36PM PDT, ID: 21458776

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 02:14AM PDT, ID: 21469086

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 02:19AM PDT, ID: 21469106

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 02:54AM PDT, ID: 21469228

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 03:15AM PDT, ID: 21469296

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 03:54AM PDT, ID: 21469457

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628