Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:03:30+00:00 2026-05-26T14:03:30+00:00

I am trying to change the date format in a text file so that

  • 0

I am trying to change the date format in a text file so that it can be comma-delimited by Year, Month, and Day. Currently, it is in YYYY-MM-DD format and I am trying to replace the hyphens with commas without affecting the other hyphenated text in the file:

2011-1-1,59,44,29,55,42,26,93,80,66,30.15,30.05,29.96,10,8,4,14,3,22,T,7,Rain,201,39.2,76.7,KBWI
2011-1-26,35,34,32,34,31,25,100,82,64,30.04,29.79,29.54,9,2,0,22,11,29,1.82,8,Fog-Rain-Snow-Thunderstorm,23,39.2,76.7,KBWI #I dont want to remove the hyphens for the weather events

A friend told me to use regex with this expression:

re.findall('[\d]{4}-[\d]{1,2}-[\d]{1,2}')

It does find the patterns for all the dates formatted with hyphens, but I have no clue as to how to replace the hyphens with commas for all the lines in the textfile with this match. I’m thinking about creating a new text file with the edited data so that I can use it in another application. Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:03:30+00:00Added an answer on May 26, 2026 at 2:03 pm

    Without using regexp is simple:

    in = open("inputfile", "r")
    out = open("outputfile", "w")
    
    for line in in:
        line = line.split(",", 1)
        line[0] = line[0].replace("-", ",")
        out.write(','.join(line))
    
    in.close()
    out.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to change this timestamp 2010-08-02 00:28:20 to month/day/year - 08/02/10 ..in the
I'm trying to change the format of the month that displays in the popup
Im trying to change a custom date format to dd/mm/yyyy. The code below works
I am trying to change the date format in the JQM UI Datepicker. It's
I am trying to simply change the date format from the datatable to universal
I'm using date picker. I'm trying to change the format of date but I
I am trying to change my date format var d = new Date(); var
I am trying to convert a uncommon date format into a standard date. Basically
What I'm trying to do is automatically change the output format of dates in
I'm trying to format a date for a given locale new Locale(mk, MK) .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.