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.

Answers were Sorted based on User's Feedback



Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / thiru

Above answers allow 09:2332:19811981 input also to display.
Following may use to avoid that issue
grep -o '[0-9][0-9]:[0-9][0-9]:[0-9][0-9][0-9][0-9]' infile.txt

Is This Answer Correct ?    44 Yes 6 No

Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / uttamjit

You can use the below command:
grep -o '[[0-9]*:[0-9]*:[0-9]*' infile

where infile is the input file to grep command.

Is This Answer Correct ?    16 Yes 12 No

Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / sona shaw

grep, egrep, fgrep - print lines matching a pattern
SYNOPSIS
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
e.g
grep "24:02:2010" date.txt
o/p is :hi today is 24:02:2010

here we should keep the matching patten in double
qoute"xxxxxxxx" and date.txt is inputfile in which u have
to search the pattern. for more details see manual page of
grep.type man grep and see various option

Is This Answer Correct ?    4 Yes 2 No

Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / mo

#1: grep '[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]'
<filename> | more

from #1 output see which column is returned for date.

use next this command.

#1: grep '[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]'
<filename> | cut -f<from the first command> -d"<Delimeter
of file>

Is This Answer Correct ?    2 Yes 0 No

Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / 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

Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / mad

Small modification required

grep -o '[0-9]*:[0-9]*:[0-9]*' infile

Is This Answer Correct ?    5 Yes 12 No

Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / shweta

grep -v "[Aa-Zz]" exp.txt

Is This Answer Correct ?    2 Yes 10 No

Hi All, Can you please let me know how to grep for a particular pattern in unix. I want to print t..

Answer / megharam

$date +DATE:%d-%m-%y

Is This Answer Correct ?    0 Yes 13 No

Post New Answer

More Unix Commands Interview Questions

How do I use grep to find a file?

0 Answers  


Give Command that will move a single file called "unix.txt"

7 Answers   IBM,


distinguish between multi-tasking,multi-user,multi- processing and time sharing?

4 Answers   Infosys, Nikhil Construction,


what is the functionality of kernel in unix architecture?

13 Answers   HCL,


what is the command to list all files in a directory, including the hidden files in UNIX ?

9 Answers   CTS,






How to set sticky bit, or it have any seperate directory to create sticky bit in sunfir servers. Please help me , i don't no the exact answer?

4 Answers   HCL, Wipro,


What is the behavioural difference between cmp and diff commands?

0 Answers  


Which command will print your home directory on screen?

0 Answers  


Write a command to display a file’s contents in various formats?

0 Answers  


What are the commands in UNIX to list the files in a Directory?

0 Answers   CGI,


distinguish between user mode and kernel mode?

6 Answers   Infosys,


What is a bash command?

0 Answers  


Categories