Wildcard for grep

GNU grep with Oracle Linux 6.3

I want to grep for strings starting with the pattern ora and and having the words r2j in it. It should return the lines highlighted in red below.
But , I think I am not using wildcard for multiple characters correctly.

$ cat someText.txt
ora_pmon_jcpprdvp1
ora_pmon_CDRTEST1
ora_pmon_CDRVP1
ora_pmon_r2jmqsit1
ora_pmon_r2jcpsit1
ora_pmon_mpiprdvp1
ora_pmon_mpisit1
ora_pmon_jcpsit1
ora_pmon_cdrsit1
$
$
$ grep ora*r2 someText.txt
$
$
$
$ grep "ora*r2" someText.txt
$

grep does not use wildcard, it uses regular expressions. So, "a*" means match "", or "a", or "aaaaaaa", or "aaaaaaaaaaaaaaaaaa", etc.

Try "ora.*r2". . has a special meaning to regular expressions -- "any character".

1 Like

It worked !! Thank You Corona.
So, the dot matches any single character in regular expressions.
What is the role of * in this ? And what is that dot (in red) doing outside the double quotes ? !!

$ grep "ora.*r2". someText.txt
ora_pmon_r2jmqsit1
ora_pmon_r2jcpsit1

It is a modifier, meaning "zero or more of the previous thing". ? means "zero or one of the previous thing", and + means "one or more ..." etc.

It ends the sentence in my previous post. It's not actually part of the expression. :slight_smile:

1 Like