However, I need flexible output not confined to one date. Like if the dates are 1 - 9 I can grep the first two values from date including the two spaces and after 9 i.e. from 10 - 31 I don't need this variable.

Actually I have made a script which will throw a mail if any error or failure messages are encountered in /var/adm/syslog/syslog.log file. The script will automatically check the date and grep the errors|failures from today's date and mail us.

First, this all seems to be a very convoluted way of getting output from the command:

Code:

date '+%b %e'

Second, if you save the output from the above command in a variable:

Code:

p=$(date '+%b %e')

and then print that value using echo without quotes, you are throwing away the fact there the date command will put two spaces between the abbreviated month name and the day of the month for the 1st nine days of every month. If you want to preserve the spacing, use:

Code:

echo "$p"

not:

Code:

echo $p

There is a big difference between being able to pass a space in a variable and getting the shell to recognize that two spaces are different that one space when you subject the contents of that variable to word splitting.

To get what you want out of the log file, there are lots of ways to do it depending on your shell. With any standards conforming shell (such as bash or ksh), try: