grep regular expression

please can someone tell me what the following regrex means

grep "^aa*$" <file>

I thought this would match any word beginning with aa and ending with $, but it doesnt.

Thanks in advance

Calypso

You are right!

The command filter contains only lines which start with "aa"!

this

echo "aaaa" | grep "^aa*$"

returns aaaa

but this

echo "aaa1" | grep "^aa*$"

returns nothing

Calypso

Nope, the "grep" regex matches all the lines in <file> that have one or more a's and nothing other than a's.

$
$ cat -n input.txt
     1  a
     2  aa
     3  aaa
     4  aba
     5  abb
     6
     7  b
     8  A
     9  AA
$
$ grep -n "^aa*$" input.txt
1:a
2:aa
3:aaa
$
$

tyler_durden

The second command returns nothing because there is a character other than a in the input stream.

The grep regex will match only a's. And there must be at least one a.

tyler_durden

Thanks for that,

I just had one more question about grep, is it possible to match possible multiple patterns for example how could i say find lines that match

  1. "^aa.*$" AND ends with "aa"

  2. "^aa.*$" OR ends with "aa"

Thanks
Calypso

grep "^a*aa$" <file>
egrep "^aa*$|aa$" <file>

tyler_durden

Thanks again tyler