Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-13-2010, 08:33 PM   #1
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Rep: Reputation: 9
Question grep not recognizing all the meta-characters when used with -e option.

Hi All,

I was trying to use the grep command with -e option to test some regular expressions with it but to surprise not all the meta characters were being recognized by the grep engine, how ever egrep works perfectly fine.

For example : The following egrp command works fine

egrep -i [0-9]+[a-z][0-9]? Testfile

but grep -e [0-9]+[a-z][0-9]? Testfile does not work fine it works without meta characters like '+' '?' '*'.

So could anyone explain this behavior of grep command
Old 10-13-2010, 08:51 PM   #2
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,701

Rep: Reputation: 566Reputation: 566Reputation: 566Reputation: 566Reputation: 566Reputation: 566
yes, from the man page

       -E, --extended-regexp
              Interpret PATTERN as an extended regular  expression  (ERE,  see  below).   (-E  is
              specified by POSIX.)
       -e PATTERN, --regexp=PATTERN
              Use PATTERN as the pattern.  This can be used to specify multiple search  patterns,
              or to protect a pattern beginning with a hyphen (-).  (-e is specified by POSIX.)
you want grep -E.
Old 10-14-2010, 12:14 AM   #3
Registered: Oct 2010
Distribution: Red Hat
Posts: 228

Original Poster
Rep: Reputation: 9
Thumbs up

First of all thanks for the reply.

I know it works with E option since t teats the pattern as a ERE but i am not clear with the -e option. Could you please explain how it works if possible plz quote an example.
Old 10-14-2010, 02:52 AM   #4
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 8,303

Rep: Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249Reputation: 2249
Basically it just means you can use multiple patterns to match:
$cat f2.txt


$grep data f2.txt

$grep -e data -e other f2.txt
Fairly basic example but demonstrates -e


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] GREP: search special characters carolflb Linux - Newbie 4 02-10-2010 05:11 AM
Recognizing Japanese Kanji characters: looking for tutorial. ErV General 5 02-20-2009 03:46 PM
Alt no longer META key when using in-terminal option of Emacs (emacs -nw) frznchckn Linux - Software 1 06-02-2007 03:41 AM
escapeing the characters '[' and ']' in grep logicalfuzz Linux - Newbie 3 03-21-2006 04:04 AM
Xterm and meta characters Khabi Linux - Software 1 09-20-2005 05:31 PM

All times are GMT -5. The time now is 06:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration