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

  • Home
  • SEARCH
  • 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 8370509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:55:45+00:00 2026-06-09T13:55:45+00:00

I have a file with rows of an SQL dump. It has dates in

  • 0

I have a file with rows of an SQL dump. It has dates in the format yyyy-mm-dd (eg. 2012-08-13)

I’d like to replace all those dates with a marker so that in the future I can populate the database with rows that are all centered around the date at the time.

For example

  • 2012-08-13 I want to change to be stored as something like $$MAINDATE$$
  • 2012-08-14 I want to be $$MAINDATE+1$$

This way they are all stored relative to a single date and the data will make sense backwards and forwards off the new creation date.

Then I’d like to iterate the file and replace them all with a new date based on an argument at the time. And adjusted dates based on the +1 or +100 or however many days away it will be at the end.

I think the match text is /\d{4}-\d{2}-\d{2}/

But how do I replace the text that is matched with a new term taking up and replacing the old text?

Update:

I used this to change the markers back to dates.. I doubt its pretty but its working

#iterate each line and look for the marker
while (line = infile.gets)
 str = line
#replace marker with data modified by the modifier
rules = Hash[str.scan(/(\$\$MAINDATE(\+|\-)\d{1,5}\$\$)/).uniq.collect do |e| 
    modifyValue = e[0].split(e[1])[1].gsub("$","").to_i
    if e[1] == "-" then
        modifyValue = modifyValue * -1 
    end
    [e[0], (today + modifyValue).to_s] 
end    ]
  rules.each do |key, value|
    str.gsub!(key, value)
  end
#write new line to array
finishedText.push str
end
  • 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-06-09T13:55:46+00:00Added an answer on June 9, 2026 at 1:55 pm
    require "date"
    
    def format_log(str, marker, refdate)
      rules = Hash[str.scan(/\d{4}-\d{2}-\d{2}/m).uniq.collect{|e| [e, (Date.parse(e)-refdate).to_i]}]
      rules.each do |key, value|
        replacement =  "%s%s" % [value >= 0 ? "+" : "", value]
        str.gsub!(key, marker % replacement )
      end
      str
    end
    
    p format_log("2012-08-13\n2012-08-14\n2012-08-12", "$$MAINDATE%s$$", Date.today)
    

    will output

    "$$MAINDATE+0$$\n$$MAINDATE+1$$\n$$MAINDATE-1$$"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 3 million rows customers.csv file. When I import it in SQL 2008,
Little Background: I have csv file which has lots of rows and each row
I have an SQL Express file with a single table People. People has six
I have a full MS SQL Backup file that I would like to extract
I'm trying to insert rows using raw sql in django: The input file has
I have a csv file with 350,000 rows, each row has about 150 columns.
I have an SQL file containing two tables with around 600,000 rows altogether. Yesterday,
I have a txt file containing multiple rows of identical size: (Examples) 0123456 789
I have a data file which is comprised of rows of data, newline separated.
I have an excel file with 10,000 rows in column A some values are

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.