I am trying to copy lines from a log file from certain days.

Here's an example of what they look like.

2014-05-01T15:53:16+00:00 DEBUG (7): 

2014-04-301T11:08:10+00:00 DEBUG (7):

This GREP command works but only for exact strings:

grep -w '2014-04-30\|2014-04-29\|2014-04-28\|2014-04-27\|2014-04-26\|2014-04-25\|2014-04-24\|2014-04-23\|2014-04-22\|2014-04-21\|2014-04-202014-04-19' /test_custom.log > new_file.log

When I try to add the wildcard, it doesn't work. I also tried several other ways with same result.

grep -w '2014-04-30*\|2014-04-29*\|2014-04-28*\|2014-04-27*\|2014-04-26*\|2014-04-25*\|2014-04-24*\|2014-04-23*\|2014-04-22*\|2014-04-21*\|2014-04-20*' /test_custom.log > new_file.log

Any suggestions?


* in a regular expression has a different meaning than in a filename wildcard. * means repeat the preceding thing zero or more times. To just say "anything", you have to use .*, where . stands for "any character".

Moreover, if you want all lines that start with the dates, drop the -w and add ^ to match the beginnings of lines:

grep '^\(2014-04-30\|2014-04-29\|2014-04-28\|2014-04-27\)'

The dates are enblosed in parentheses so you don't have to repeat the ^ every time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.