1822959 Members
3665 Online
109645 Solutions
New Discussion юеВ

Re: grep pattern

 
SOLVED
Go to solution
Dave Chamberlin
Trusted Contributor

grep pattern

I have some files with a date sring of the format "01-10-99" in them. I can do cat myfile | grep '01-' to get all in Jan, or cat myfile | grep '\-99' to get all in 99, but I can't find a grep pattern match to get all jan 99 - ie '01-*-99' does not work, although it does work if I am using ls | grep a*c etc. What am I missing?
4 REPLIES 4
Kevin Wright
Honored Contributor

Re: grep pattern

i do not think grep or egrep allows an 'and' character, another way to do this is...
grep 01 > /tmp/jan
grep 99 /tmp/jan

however,the 'or' is allowed
egrep 'exp1|exp2' file
Christopher Caldwell
Honored Contributor
Solution

Re: grep pattern

01-10-99
egrep "01-[[:digit:]][[:digit:]]-99"
Dave Chamberlin
Trusted Contributor

Re: grep pattern

thanks for the quick responses - chris' solution works just fine!
Thierry Poels_1
Honored Contributor

Re: grep pattern

Hi,
less foolproof, but less typing work ;)

grep "01-..-99" yourfile

regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.