Shell Variable in Curly Brackets Returns Empty Value

Hello Team,

I have a script which will grep for a time from a file. I have following code to grep for a time in a file.

node=`hostname`

current_date=`date`

file11=weblogic.log

next_date=`date '+%b %e, %Y'`

next_date_time11=`grep -i "${#next_date}" ${file11}| tail -1 | awk '{print $4}'`

When I do echo to variable next_date_time11 it returns null value.

I am trying to get time from the below file. I am unable to do that.

Kindly help

Below is the file content :-

<May 2, 2012 1:14:50 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport
<May 2, 2012 1:17:53 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport

Hi: ${#next_date} means length of string $next_date . Does your input file contains newlines like that?

Hello ,

Thanks for the response.

My file contains following line in it.

<May 2, 2012 1:14:50 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport
<May 2, 2012 1:17:53 PM MEST> <Error> <HTTP> <BEA-101214> <Included resource or file "/eMatrix/jsp/mars/report/optionFragments/baseline_options.jsp" not foun
d from requested resource "/eMatrix/jsp/mars/report/report.jsp".>
submitMode=viewreport

I would like to get the time stamp "1:14:50" from the file.

Kindly help

In the log file there is only one space between May and 2. You can try: date '+%b%e, %Y' but I don't know if that would work for double digit days of the month..