How to write a shell script to direct grep data to a file name based on date?

I basically want to do this:

grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log

... with, of course, the file name example.com.2008-09-27-11: 21: 30.log

Then I put this in crontab for daily launch.

+5
source share
3 answers

Detailed method:

grep 'example.com' www_log > `date +example.com.%Y-%m-%d-%H:%M:%S.log`

Close method:

grep 'example.com' www_log > `date +example.com.%F-%T.log`
+9
source
grep 'example.com' www_log > example.com.$(date +%F-%T).log
+5
source

, :

grep 'example.com' www_log > example.com.`date +%F-%T`.log

Backticks - . $():

$(command)

:

`command`
+2

All Articles