Q:

Need to convert Wed Mar 13 00:18:06 2013 into datetime in Unix

I have two variable and they are assigned to the following value 
Start_time=Start time: [Wed Mar 13 00:18:06 2013]

End_time=End time: [Wed Mar 13 00:18:12 2013]

now I need to subtract the Start_time from End_Time. So I need to first remove the other strings and convert the date into a format where I can perform the subtraction. 
For removing the strings I used the following sed function
echo "Start time: [Wed Mar 13 00:18:06 2013]" | sed -e 's|Start time:||'

[Wed Mar 13 00:18:06 2013]

How do I remove the brackets without using another sed function.
Also, can someone tell me how to convert this into a date format from which I can perform the subtract operation.

A:

The sed statement can be:
sed -e 's|Start time: \[||;s/\]//'

Using gnu date you can specify the date to be used and convert to unix timestamps
(substitute your variables for the hard coded values):
bll@bll-desktop ~
$ a=$(date --date="Wed Mar 13 00:18:06 2013" '+%s')

bll@bll-desktop ~
$ b=$(date --date="Wed Mar 13 00:18:12 2013" '+%s')

And then get the difference in seconds:
bll@bll-desktop ~
$ d=$(($b - $a))

bll@bll-desktop ~
$ echo $d
6

