views:

696

answers:

3

I basically want to do this:

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

...with of course the filename being example.com.2008-09-27-11:21:30.log

I'd then put this in crontab to run daily.

+9  A: 

The verbose method:

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

The terse method:

grep 'example.com' www_log > `date +example.com.%F-%T.log`
Michael Ridley
http://partmaps.org/era/unix/award-example-backticks.html
Mez
I think the back ticks are appropriate in this example as they are more portable and probably more universally understood which is better from a maintainable systems perspective. Although it's possible I'm missing the point of the link you posted since you didn't give any context.
Michael Ridley
my point was backticks are evil :D
Mez
+5  A: 
grep 'example.com' www_log > example.com.$(date +%F-%T).log
Mez
+2  A: 

Here is another way, that I usually use:

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


Backticks are a form of command substitution. Another form is to use $():

$(command)

which is the same as:

`command`
Tao Zhyn
Wow, I must be a slower writer. When I started there was only one answer, with a quick answer.When I finished, there is a new answer and the other one has been edited. Both happened with in the last 10 minutes.
Tao Zhyn
http://partmaps.org/era/unix/award-example-backticks.html
Mez
@Martin the website you link to has no relevance. This is not a useless use of backticks.I think what you might be saying, is that backticks have been superseed by $().http://doc.async.com.br/abs-0.3/HTML/backticks.html
Tao Zhyn
In classic C shell and classic Bourne shell, back-ticks are available and $(...) is not. The new notation is better when available, not least because it is far easier to understand nested invocations.
Jonathan Leffler