Quote:
Originally Posted by hristo77
Hi,
Im trying to grep for yesterdays date like this
Code:
cat logfile_rman.log | grep '\-*' -A 5 | grep 'date +%Y%m%d -d yesterday' -A 500 | grep 'RMAN-' -C 1 | wc -l
Tried this as well:
exp_date=$(date +%Y%m%d -d yesterday)
cat logfile_rman.log | grep '\-*' -A 5 | grep '$exp_date' -A 500 | grep 'RMAN-' -C 1 | wc -l
The code works if I replace date with '20151104', I then get a wc of 20.
Whats wrong?
Regards
H
|
Hi!
Get rid of the single quotes in your grep.
Like this:
Code:
echo "foo 20151104" | grep $exp_date
foo 20151104
As you can see, this works as expected. But not:
Code:
$ echo "foo 20151104" | grep '$exp_date'
^This returns nothing.
Edit:
To add to the confusion, you
can use double quotes:
Code:
echo "foo 20151104" | grep "$exp_date"
foo 20151104
Bash can be very confusing at times!
Best regards,
HMW