think tank forum

technology » regexp help

lucas's avatar
17 years ago
link
lucas
i ❤ demo
dp, db, et al.: can you help me convert these dates?

i need dates like these:
11.01a 08.25
11.51a 08.25
11.39a 08.27
6.29p 08.27
1.57p 08.31
9.25a 09.01
10.09p 09.01
9.28p 09.02
6.50p 09.03
1.44p 09.04

to look like these:
2004-09-06 03:12pm
2004-09-15 10:23am
2004-09-27 11:54am
2004-09-29 05:03pm
2004-10-10 02:56am
2004-10-11 10:12am
2004-10-11 01:32pm
2004-10-12 09:44am

they are all from 2004. first to bust a regexp wins a triple threat
 
17 years ago
r1, link
dbrown
this post has been archived.
 
17 years ago
r1, link
dbrown
this post has been archived.
 
17 years ago
r1, link
dbrown
this post has been archived.
 
17 years ago
r1, link
dbrown
this post has been archived.
 
17 years ago
r1, link
dbrown
this post has been archived.
 
17 years ago
link
dbrown
i'm sorry for anyone who has read through all my posts

man i suck, grep is in fact the completely wrong command to use there and my regexp is incorrect. the good news is that a script is no longer needed. here's what i meant to say:

cat input file | sed 's;\([[:digit:]]*\)\.\([[:digit:]]*\)\([[:alpha:]]\).\([[:digit:]]*\)\.\([[:digit:]]*\);2004-\4-\5 \1:\2\3m;' >> output file

you'll have to forgive me as i was at a party on someone else's computer when i wrote the original one. i realized the error of my ways on the way home. now that i am home it is tested and working.

--console output start--

[dbrown@expo86 ~/bin]$ cat input
11.01a 08.25
11.51a 08.25
11.39a 08.27
6.29p 08.27
1.57p 08.31
9.25a 09.01
10.09p 09.01
9.28p 09.02
6.50p 09.03
1.44p 09.04
[dbrown@expo86 ~/bin]$ cat input | sed 's;\([[:digit:]]*\)\.\([[:digit:]]*\)\([[:alpha:]]\).\([[:digit:]]*\)\.\([[:digit:]]*\);2004-\4-\5 \1:\2\3m;' >>output
[dbrown@expo86 ~/bin]$ cat output
2004-08-25 11:01am
2004-08-25 11:51am
2004-08-27 11:39am
2004-08-27 6:29pm
2004-08-31 1:57pm
2004-09-01 9:25am
2004-09-01 10:09pm
2004-09-02 9:28pm
2004-09-03 6:50pm
2004-09-04 1:44pm

--console output end--
lucas's avatar
17 years ago
link
lucas
i ❤ demo
djb saves the day! thanks, man
 
17 years ago
link
dbrown
woot!
dannyp's avatar
17 years ago
link
dannyp
dʎuuɐp
quick with it, I didn't even see the thread until it was complete!
lucas's avatar
17 years ago
link
lucas
i ❤ demo
i wanted leading zeros on the hours, but that was quick for me to change by hand.
 
17 years ago
link
dbrown
better have that triple threat ready when i hit bz tomorrow!
lucas's avatar
17 years ago
link
lucas
i ❤ demo
oh shit! haha
lucas's avatar
17 years ago
link
lucas
i ❤ demo
damn, db. didn't get you that triple threat action yet! bro, i'm gonna roll caitlin back to bmt one of these days and we'll all have to hang out together. and i promise a bmt-based triple threat.
 
17 years ago
link
dbrown
i'm down, hit me up!