Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some files in a directory that contain dates that are formatted like:

December 29 19:05:58

But they differ referring to the date that the file was created.

Is there any way to do a search-replace on these files to replace the dates with ones that look like:

December 29 2010 19:05:58

I am on Mac OS X.

EDIT: To clarify, any scripting would be fine, i.e: sed or shell/ruby scripts.

share|improve this question
up vote 1 down vote accepted

I don't think it's possible without a powerful text editor or some scripting.

Use the following regular expression in TextMate:


(January|February|March|April|May|June|July|August|September|October|November|December) (\d{1,2}) (\d{2}:\d{2}:\d{2})

Replace with:

$1 $2 2010 $2

Depending on the number of files scripting would be faster. I'd opt for an editor like TextMate if it's not too much work -- this way, you get to check each substitution before you save.

For the sake of completeness:

cat src.txt | sed "s/\([A-Z][a-z]\{1,\} [0-9]\{1,2\}\) \([0-9][0-9]:[0-9][0-9]:[0-9][0-9]\)/\1 2010 \2/g" > dest.txt

People who use sed regularly may laugh now, I don't care.

share|improve this answer
Scripting is fine, so would sed work? – Wuffers Jan 9 '11 at 19:52
@Mark I'm not a sed user -- maybe wait a few minutes ;) – Daniel Beck Jan 9 '11 at 19:53
Ok, I will, Thanks! – Wuffers Jan 9 '11 at 19:53
@DanielBeck: I think I'll try out the trial of TextMate for this purpose, I'll let you know how it goes. – Wuffers Jan 9 '11 at 20:00
Awesome! That worked! Thanks! – Wuffers Jan 9 '11 at 20:09

Try this (for OS X, replace the -r with -E):

sed -r 's/(January|February|March|April|May|June|July|August|September|October|November|December)( [0-9 ][0-9] )(([0-9][0-9]:){2}[0-9][0-9])/\1\22010 \3/'
share|improve this answer
Wouldn't all these parentheses need escaping? – Daniel Beck Jan 9 '11 at 20:26
@Daniel: Not with -r or -E. – Dennis Williamson Jan 9 '11 at 20:30
Thanks for the info. – Daniel Beck Jan 9 '11 at 20:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.