Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the date format for grep -E in Unix

I write the dates on my file with the next format

date +%a-%b-%d-%Y

My goal in my exercise is to get the list of the dates in my file. I know I need to do it with grep -E, but I don't know how to put correctly the format of the date.

Desired input:

"grep -E (the format of the dates I'm looking for)" ~/file1

Desired output:

Tue-Oct-15-2013
Wen-Oct-16-2013
Wen-Oct-16-2013
Thu-Oct-17-2013
like image 843
Dor Zohar Avatar asked Sep 05 '25 17:09

Dor Zohar


1 Answers

Try following:

grep -E '[[:alpha:]]{3}-[[:alpha:]]{3}-[[:digit:]]{2}-[[:digit:]]{4}' ~/file1

Or more concise

grep -E '\w{3}-\w{3}-[0-9]{2}-[0-9]{4}' ~/file1
like image 114
jkshah Avatar answered Sep 07 '25 16:09

jkshah