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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With