I am trying to use grep -w something as shown below.
grep -w "$a" $LOG1
It is not giving me neither any error nor any data. I am facing the issue while i run this command inside a script. But i am getting the data if i run the above command outiside the script.
here $a=08/11/2009 21
i tried outisde something like this and is working.
grep -w "08/11/2009 21" $LOG1
Can someone help me with the grep -w inside the script?
I am sorry for the confusion. That line a=08/11/2009 21' should be replaced with a=$express.I will update my post also accordingly.
And i am using the total script to get 5 hrs back data. And the date format in the file is something like this
08/11/2009 09:00:00
---------- Post updated 08-12-09 at 01:37 AM ---------- Previous update was 08-11-09 at 11:52 PM ----------
If it goes to the else condition The above code is working fine. Seems to be an issues with white apces in if part of the code.
here is the code that i am using to grep for 5 hrs back data. As a part of it..if it goes to the else loop it is working fine. but the data is picked by grep if the code executes th efirst pasrt of teh code(i.e, if loop suuceeds)
p.s. In both the cases i am able to echo date format correctly. Not sure this may be a space issue.
#!/bin/bash
genexpression()
{
stime=`date '+ %H'`
if (( $stime < 5 ))
then
stime=`expr $stime \+ 19`
export express=\(`TZ=CST+24 date '+ %m/%d/%Y'`\ $stime
else
stime=`expr $stime \- 5`
if (( $stime < 10 ))
then
stime=0${stime}
fi
export express=`date '+%m/%d/%Y'`\ $stime
fi
}
genexpression
export express
echo $express
t=`grep -w "$express" Service.log | wc -l`
if [ $t -ne 0 ];then
echo "suces"
else
echo "fail"
fi
i don't think the issue is with grep, as i am getting the data if the else part of the code is executed.
The only issue is with first part of the code which i am using to get the yesterday's data, if the current time is less than 5 am.(as i njeed to get 5 hrs back data)
The first part also is printing the $ express correctly. There should an issue with the space somewhere which is causing ultimately grep not to pick any data.
if (( $stime < 5 ))
then
stime=`expr $stime \+ 18`
export express=`TZ=CST+24 date '+%m/%d/%Y'`\ $stime
The awk statement is still giving me bailing out error. i am not sure if it is an issue because my box is SunOS.
Apart from this, the grep -w that you have suggested is working fine for both the instances finally.(it was not working for maual runs. I tried by cronning the script and it just worked fine. Not sure what was the issue when i run it manually. )