How to extract date with time from file

Hi,

I have a file where there is a date and time field, the format for it is yyyy-mm-dd hours:mins:sec

the position of date field may vary anywhere in the line and it might be different and it is specified along with the variable AppTimeStamp

how do i extract date and time both from the line

for eg .

xxxxxxxxxxxxxxx<AppTimeStamp>09-10-2006 12:10:01<\AppTimeStamp>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<AppTimeStamp>10-12-02 10:05:00<\AppTimeStamoxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Please can anybody help me with this

You might want to check this link.

Please use the search utility in this forum. You will find quite a number of threads useful regarding date manipulation

Hi,

Thanks for the link,

I tried the same, but it did not work,

here is the sample file i am using
<xxxx><xxxxx><xxxxx><AppEventTimeStamp>2006-05-02 09:25:00</AppEventTimeStamp><xxxx><xxxx>345</xxx><AppEventTimeStamp>2006-10-18 10:25:00</AppEventTimeStamp><xxxxxx><\xxxxxxxx>

The format i am searching for is "year-mon-day hour-min-sec"

could you please help me out with this

Just change the search pattern present in the above link mentioned by misenkiser
sed 's/^.\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} [0-2][0-4]:[0-5][0-9]:[0-5][0-9]\).$/\1/' file name

Python Alternative:

#!/usr/bin/python
import re #regular exp module
data = open("input.txt").read()
print re.findall("<AppEventTimeStamp>(.*?)</AppEventTimeStamp>",data)

Output:

['2006-05-02 09:25:00', '2006-10-18 10:25:00']

i need to extract teh date only from
INTERFACE_HEAD|2005/12/27|22:30:59|CMT|
and not the time..ie in teh format yyyy/mm/dd

can any body help