Sigularity
Sigularity

Reputation: 967

How to use a wildcard in egrep?

Can I use a wildcard '?' in egrep? I just want to print match strings starting with '02' or '03' from Data.

Tried below command, but it doesn't help.

egrep '03/??/16|02/??/16' test

Data

01/19/16
02/19/16
02/13/16
03/04/16
03/05/16

Upvotes: 2

Views: 6314

Answers (3)

Sangseo Lee
Sangseo Lee

Reputation: 11

try

egrep '0[2,3]/[0-9]{2}/16' test

this will print match strings starting with '02' or '03

Upvotes: 1

riteshtch
riteshtch

Reputation: 8769

use . instead of ? to match a single char like this:

egrep '03/../16|02/../16' test

or use proper number character classes

egrep '(03|02)/[0-9]{2}/[0-9]{2}' test

Upvotes: 1

zegkljan
zegkljan

Reputation: 8391

Have you actually looked at the egrep's man page? There is written that ? specifies that the preceding item is optionally matched at most once (i.e. zero times or once). What you are probably looking for is the . pattern which matches exactly one character.

What you need is probably

egrep '03/../16|02/../16' test

or

egrep '(03|02)/../16' test

Upvotes: 3

Related Questions