0

I have file with data fields in this format YYYY-MM-DD HH:MM:SS but I noticed the export set the Months values to be the same as the minutes value. I want to use sed to replace the Month value for all line to the same value.

I am trying this and it didn't work:

sed "s/-[0-9]{2,}-/-08-/g" test.txt

Anyone have an idea how to do this?

3
  • please give sample of input data and the wished filtered result Commented Sep 5, 2012 at 12:11
  • example data is "2012-59-30 23:59:00,94933883,-,testing". I would like that to be changed to "2012-08-30 23:59:00,94933883,-,testing" Commented Sep 5, 2012 at 12:20
  • Can you edit your post to specify what happened instead of it "working"? Just saying "it didn't work" isn't very helpful. What did you want to happen, and what happened instead? Commented Sep 29, 2012 at 17:11

2 Answers 2

1
$ sed 's/^\(....\)-../\1-09/' < input

Input:

$ cat input 
2012-52-05 09:52:00
2012-53-05 09:53:00
2012-54-05 09:54:00

Output:

$ sed 's/^\(....\)-../\1-09/' < input
2012-09-05 09:52:00
2012-09-05 09:53:00
2012-09-05 09:54:00
Sign up to request clarification or add additional context in comments.

Comments

0

With GNU sed:

sed -r 's/([0-9]{4})-[0-9]{2}-/\1-08-/' infile

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.