Using grep or egrep


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using grep or egrep
# 1  
Old 07-14-2010
Using grep or egrep

So a few months ago, I decided to move away from using grep and decided to use egrep in this code that i'm writing.

i figured egrep is more robust than grep.

well, it appears it isn't.

when i used egrep to search the log file for a script that looked like the following, egrep couldn't find the string:

Code:
(blah blah blah afafafafafaf System:) afafafafafafafa whatever

The egrep command I used was:

Code:
egrep '(blah blah blah afafafafafaf System:)'

And this command produced no output. However the grep command is able to pull out the search pattern just fine.

My question is, is there a way around this? I dont want to have to go back to grep. I want egrep to be able to do everything grep does but more. Isn't egrep a more advanced version of grep?
# 2  
Old 07-14-2010
'egrep' works as expected on Solaris9.
try:
Code:
egrep '\(blah blah blah afafafafafaf System:\)' myFile

# 3  
Old 07-14-2010
Quote:
Originally Posted by vgersh99
'egrep' works as expected on Solaris9.
try:
Code:
egrep '\(blah blah blah afafafafafaf System:\)' myFile


i dont want to have to include the "\".

this is on SunSolaris.

i guess i can search for different things on the string that egrep can pick up.

am i wrong in my belief that egrep is more powerful than grep?
# 4  
Old 07-14-2010
It simply uses extended regular expressions by default instead of basic regular expressions. You can do the same with 'grep -E'.

In extended regular expressions, parenthesis are metacharactes which are used for grouping and capturing; thus, they must be escaped if they are to be matched literally. In basic regular expressions, the parenthesis are not metacharacters and must be quoted if they are to be used to capture or group.

Although egrep defaults to using a more powerful regular expression language, the command itself is not in any way more robust ... imo.

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

grep/egrep fails with $ anchor?

The $ seems to fail for me. I'm using GNU grep 2.5.4 (that is, nothing out of the ordinary, just what came with my distro) but I can't get the final anchor $ to work for me. (^ works as usual.) Behavior without anchor: $ /bin/grep -E 'tium' file tritium tertium quid Expected behavior: $... (2 Replies)
Discussion started by: CRGreathouse
2 Replies

2. Homework & Coursework Questions

grep and egrep

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I have a text file. 1) How do I search for x and y? 'Find all lines that contain David and Emily' 2) How do I... (1 Reply)
Discussion started by: ninjagod123
1 Replies

3. Shell Programming and Scripting

grep/fgrep/egrep for a very large matrix

All, I have a problem with grep/fgrep/egrep. Basically I am building a 200 times 200 correlation matrix. The entries of this matrix need to be retrieved from another very large matrix (~100G). I tried to use the grep/fgrep/egrep to locate each entry and put them into one file. It looks very... (1 Reply)
Discussion started by: realwindfly
1 Replies

4. Shell Programming and Scripting

How to grep/awk/egrep two values for given output?

Dear Friends, I have a command which can result following output. Packet is: /var/adm/yyyy/pkt6043 Intended for network : /vob/repo I would like to retrive pkt6043 and /vob/repo using single command. Blue color test will be always contstant and red color text will be dynamic ... (2 Replies)
Discussion started by: baluchen
2 Replies

5. UNIX for Dummies Questions & Answers

Difference between grep, egrep & grep -i

Hi All, Please i need to know the difference between grep, egrep & grep -i when used to serach through a file. My platform is SunOS 5.9 & i'm using the korn shell. Regards, - divroro12 - (2 Replies)
Discussion started by: divroro12
2 Replies

6. UNIX Desktop Questions & Answers

Difference grep, egrep and fgrep

Hi All, Can anyone please explain me the difference between grep, egrep and fgrep with examples. I am new to unix environment.. Your help is highly appreciated. Regards, ravi (2 Replies)
Discussion started by: ravind27
2 Replies

7. Shell Programming and Scripting

Ecaping a line feed in grep/egrep

Is it possible to use the escape sequence: \r to match a line feed in grep/egrep? I want to use a regexp that crosses over two lines, and it does not seem to be possible. (1 Reply)
Discussion started by: Enobarbus37
1 Replies

8. Shell Programming and Scripting

grep/egrep end of pattern

Hi I use arp to get the mac-addresses of my hosts. # arp -a | grep 192.168.0. e1000g0 192.168.0.1 255.255.255.255 o 00:00:00:00:00:01 e1000g0 192.168.0.11 255.255.255.255 o 00:00:00:00:00:02 e1000g0 192.168.0.2 255.255.255.255 ... (12 Replies)
Discussion started by: domi55
12 Replies

9. Shell Programming and Scripting

egrep/grep result of more files

hi , I'm new at unix bash scripting, im playing a little bit with egrep/grep. I have serveral files and i do a search on those files, like "aki", the result is many rows outcoming and serveral of them are dubble because aki wil come more than ones in a file, how can i get a result that it... (3 Replies)
Discussion started by: tvrman
3 Replies

10. UNIX for Dummies Questions & Answers

grep/awk/egrep?

Hi, The input file "notifications" contains the following string. FRTP has 149 missing batches I want to search for : FRTP has missing batches As the number 149 is not important and will change. The commands I have tried. grep "FRTP has.*missing batches" notifications.txt... (3 Replies)
Discussion started by: whugo
3 Replies
Login or Register to Ask a Question