as diu
as diu

Reputation: 1080

How to grep date in mm/dd/yy where dd can be any in bash?

I'm trying the following and unable to get the desired results:

cat sfd_log.txt | grep '12/*/17' | more

My objective is to get all December 2017 entries from the file. Thank you.

Upvotes: 1

Views: 941

Answers (1)

bishop
bishop

Reputation: 39374

grep uses (optionally extended) regular expression syntax. Bash uses globbing. Similar enough to be confusing, but different enough to be important:

grep '12/.*/17' sfd_log.txt | more

Or, more precise if you like:

grep -E '12/[0-9][0-9]?/17' sfd_log.txt | more

What you actually asked for with "12/*/17" is:

a literal '12' followed by 0 or more literal '/' followed by a literal '/17'".

Upvotes: 1

Related Questions