change date stamp in a flat file

I have a flat file which has columns to be exported to a oracle table, this flat file has inside date format in the form of 2006-02-01 and 2006-02-28, I wanted to change every line that has this date format (could be any day during the month of feb) to start date as 2006-02-01 and 2006-02-07 since I want to restrict data being copied to just 7 days.

This was a problem to do manually since the file is large and also the start and end dates can be any date between 01 to 28 for the month of february.

Is there any way to do this using command line commands. Unix on which I am trying is LINUX.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

perl -i -pe 's/(200\d-02-)(\d\d)/sprintf"$1%02d",$2>7?7:$2/eg' file
mahjagAuthor Commented:
do we need to have perl for this command, I dont think I have that?
You could probably do it in awk, Linux usually has a perl
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

you can use the touch command
using awk, assuming that your date is the second column (columns are space seperated):

awk '($2!~/^2006-02-0[1-7]$/{$2="2006-02-07";}{print}' file

sed would be fine to, but it struggles with huge files, usually ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
That would also change days in January or March to 2006-02-07
but perhaps that's what you want.
You don't really say what you would want to do if you see anything other than "2006-02-01 and 2006-02-28"
> That would also change days in January or March to 2006-02-07
I assumed one world's standard format of writing dates, not the proprietary scary uncle Sam format ;-)
That would also change 2006-01-07 or 2006-03-28 or 2007-02-28 to 2006-02-07
I interpreted the question to mean that the first two to be unchanged and the third to be changed to 2007-02-07
I'm still not sure what the intended interpretation was.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.