LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 10-13-2010, 07:33 PM   #1
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 224

Rep: Reputation: 7
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, 07:51 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,598

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

Code:
       -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-13-2010, 11:14 PM   #3
Rohit_4739
Member
 
Registered: Oct 2010
Distribution: Red Hat
Posts: 224

Original Poster
Rep: Reputation: 7
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, 01:52 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874Reputation: 1874
Basically it just means you can use multiple patterns to match:
Code:
$cat f2.txt
ssomejunk 
A
B
in


other 
somestring 
  
     
data 

$grep data f2.txt
data

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


Reply


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 04:11 AM
Recognizing Japanese Kanji characters: looking for tutorial. ErV General 5 02-20-2009 02:46 PM
Alt no longer META key when using in-terminal option of Emacs (emacs -nw) frznchckn Linux - Software 1 06-02-2007 02:41 AM
escapeing the characters '[' and ']' in grep logicalfuzz Linux - Newbie 3 03-21-2006 03:04 AM
Xterm and meta characters Khabi Linux - Software 1 09-20-2005 04:31 PM


All times are GMT -5. The time now is 01:31 AM.

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