date and time in mm/dd/yyyy hh:mm format

Frens,

I have a logfile which has got manier things in it and somewer in that file i have a date in mm/dd/yyyy hh:mm format....

I just need to get the date and time nothing else....

i have searched in this forum for it but got only date in mm-dd-yyyy format..

but i need to search for mm/dd/yyyy format... i badly in need of it...

please help me bro's.... i think i shud use sed command for this but m very bad in that... pls help me..

Thank you.
Regards
Deepu

Provide a snippet of log file so that the exact cmd can be given

Basically you can use something like this:

echo "mm-dd-yyyy"| sed 's/-/\//g'
mm/dd/yyyy
# or
echo "mm-dd-yyyy here comes the ultimate-rest"| awk '{gsub(/-/,"/",$1); print}'
mm/dd/yyyy here comes the ultimate-rest

But it might be better if you post a whole line using code tags of your input file.

bro,

i shud not give any particular date while searching bcos the date varies from one logfile to other so i shud extarct the date from logfile... that too in mm/dd/yyyy hh:mm format.. pls help me in this...

EXAMPLE:

Hi

This is just for example..

This was sent by Ezzat on 10/15/2009 12:48 .....

COnsider this example and do the needful..

Thank you.
Regards.
xxxxxx

so in the above example there is a date and time which i need to extarct.. and this date n time may be different for different logfiles....

[house@leonov] echo "This was sent by Ezzat on 10/15/2009 12:48 ....." \
[............] | egrep -o "[0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2}"
10/15/2009 12:48

it is not working for me. Giving error as illegal option -o.

and do I need to use [house@leonov] [............] these 2 things? no right?

Please help me

To get better answers, please give info about your OS environment.

sed -n 's+.*\([0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]\).*+\1+p'

If the "s+...+...+" doesn't work, replace "+" with "/", "/" with "\/".

superb binlib brother... it is working fine...

but the problem here is i got 3 results out of which first one i need to select.. and also depending on AM or PM i should change the time to 24 hr format... How can i do that??

the result what i got is


10/15/2009 12:48
10/14/2009 03:18
10/14/2009 03:16

sed -n -e 's/ 12:\([0-9][0-9]\) AM/ 00:\1/' -e 's+.*\([0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]\).*+\1+p'

Thanks for your kind reply brother... will this work if the time is in PM???

The above code is working fine but need some more modification..

Like the time I have may contain AM or PM and depending on that it should change that to 24 hr format..

and something extra i need is..

As i told you before I have a file which contains manier lines and somewhere in between I have a line


Forwrded by Deepak on 11/12/2009 10:48 PM EDT

                    or

Forwarded by Deepak on 10/12/2009 11:30 AM AST

                            or

Forwarded by Deepak on 10/12/2009 11:30 AM 

where EDT=eastern Std Time
AST=Asian Std Time
if nothing is there after AM/PM then it should consider it as AST and do accordingly

Now the output I need is

Date in dd/mm/yyyy format which is there in input..

Time in HH:MM in 24 hr format and if it is AST then it should deduct 9.5Hrs from the actual time...

So as per the 1st example above

the output i should get is


11/12/2009 22:48

and for the 2nd example


10/12/2009  02:00

for the 3rd example

10/12/2009  02:00

Please give me the shell script for this.....

Thank you.

---------- Post updated at 07:58 PM ---------- Previous update was at 08:34 AM ----------

No reply at al!!!

Please help me freinds... Please give me the script for above post

---------- Post updated 11-02-09 at 06:49 PM ---------- Previous update was 11-01-09 at 07:58 PM ----------

Nobody here knows about this or what?? If so please let me know...so that I can try for other alternatives where i can get the info.

---------- Post updated 11-03-09 at 03:38 AM ---------- Previous update was 11-02-09 at 06:49 PM ----------

heloooooooo no one is hearing me :frowning:

---------- Post updated at 07:04 AM ---------- Previous update was at 03:38 AM ----------

I think you people didnt understand my requirement..

Ok leave it..Atleast tell me how can i get the below one please..

input

Forwarded by deepak on 11/17/2009 12:34 PM EDT

output

11/17/2009 12:34 PM EDT

waiting for your reply.