LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Regular Expression + not Working with grep (http://www.linuxquestions.org/questions/linux-general-1/regular-expression-not-working-with-grep-456756/)

scottwmackey 06-20-2006 08:21 PM

Regular Expression + not Working with grep
 
Does anybody know why the last grep doesn't return anything?

Code:

[smackey@copper ~]$ uname -a
Linux <deleted> 2.6.9-5.ELsmp #1 SMP Wed Jan 5 19:30:39 EST 2005 i686 i686 i386 GNU/Linux

[smackey@copper ~]$ cat my_test.txt
abcdefg

[smackey@copper ~]$ grep 'a.*e' my_test.txt
abcdefg

[smackey@copper ~]$ grep 'a.+e' my_test.txt

[smackey@copper ~]$


pixellany 06-20-2006 10:43 PM

in bash, the "+" is not recognized as a special character unless you specify extended regular expressions by using "grep -E" or "egrep"

Bash Guide for Beginners, Machtelet Garrels .....avail. at tldp.org

scottwmackey 06-21-2006 01:31 AM

Thanks much. egrep works like a charm. But now I feel like a complete idiot. I was looking at the man pages for grep, saw the egrep variant right there at the top, but I must have figured it was far too much work to try the command. Hell, it might not have worked and I would have wasted a whole key stroke. Much easier to search the web for an hour and then post to a forum. Thanks again.

Scott


All times are GMT -5. The time now is 12:48 PM.