I have a bunch of files that are messages in my directory. Each message has a date located in the file. How can I look into each file and find the date?
Thank you for any help
Are you taking about arbitrary dates or one in specific? Do you have a format for the day? Do you know if that day is in a particular line?
Random dates but this it the format: 01/25/2004
The quickest and naive approach would be:
grep -re '[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]' *
Of course, that might return what appears to be a date format pattern that it is not valid, if exists, like 99/99/9999
Yea that is true, but I am just playing around with these files. But if I was in a directory how would I search through each individual file to do that? What would I put before that grep statement?
Just like that. the flag -r in grep tells it to do recursive.
1 Like
Is there a way I can set each part of the date to month, day, year?
You can change the pattern to whatever you wish
grep -re '01/04/2014' *