I want it to find lines that contain any number of capital letters before P
this is what I have tried
echo "AAAAAP" | grep '[A-Z]P'
echo "AAAAAP" | grep '[A-Z]\{1\}P'
echo "AAAAAP" | grep '^[A-Z]*P'
But none of them seem to work, any help is much appreciated
thanks
Calypso
Do the capital letters have to begin at the start of the line? IF yes --
echo "AAAAAP" | egrep '^[A-Z]+P'
Thanks a lot!, works a charm
please could you just explain why it only works with egrep and not the normal grep
also please could just confirm the following
^ means must start with pattern
+ means one or more occurence of pattern
Thanks again
Calypso
That's because of that pesky "+" character, which means "one or more occurrence" and is an extended regex and hence supported by egrep (extended grep). Check the man page for egrep in your system.
The equivalent regex for this in grep would be:
$
$ echo "AAAAAP" | grep '^[A-Z][A-Z]*P'
AAAAAP
$
tyler_durden