Hi All, Can you please let me know how to grep for a
particular pattern in unix. I want to print the dates from
the file exp.txt. the date pattern is DD:MM:YYYY, I just
want to print all the dates from the file exp.txt.

Answer Posted / venkat

grep -o -P '(([0-2][0-9]|3[01]):([0][1-9]|[1][012]):[12][09][0-9][0-9])'

use Perl regex to validate the limits of date and month.

Pitfall: it might miss 31st of feb

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is awk command used for?

599


Which command is used to copy files?

556


What is awk used for?

616


What are grep patterns?

576


How do I find previous commands in unix?

592






What is ctrl d?

594


how to sort the content of the file based on numeric values

1250


What does 'mkdir' command do in UNIX?

660


What is the use of awk command in unix?

581


How do you repeat a command in terminal?

587


What does the command '$ls | wc –l > file1' do?

678


Which unix command lists files/folders in alphabetical order?

614


Write a command that will find all text files in a directory such that it does not contain the word "amazing" in any form (that is, it must include the words amazing, amazing, or amazing)?

954


How do I use grep to find a file?

579


How do I open a port?

589