LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-15-2002, 02:27 AM   #1
Barbarian
Member
 
Registered: Nov 2001
Location: Malaysia and Manchester
Distribution: Red Hat
Posts: 46

Rep: Reputation: 15
Question Using egrep


I've just starting fiddling with regular expressions and thought I understood enough of the basics to try a few test routines. However, I seem to be stuck on whitespaces.

I've tried the following command:-

egrep -i 'head.[0-9]+\.[0-9]+;' test.me,v

Ok, the present version will match any character after the head, but I can't seem to get it to match on a tab or space. I've tried {:space:], ( |\t)+, \t+ etc.. Why can't I match on the flipping tab? I can't see what I'm doing wrong.
 
Old 02-18-2002, 01:57 AM   #2
Barbarian
Member
 
Registered: Nov 2001
Location: Malaysia and Manchester
Distribution: Red Hat
Posts: 46

Original Poster
Rep: Reputation: 15
In answer to my own question, it appears that egrep doesn't support the shorthand metacharacters (which is a bit of a shame)
 
Old 02-18-2002, 04:16 PM   #3
Malicious
Member
 
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208

Rep: Reputation: 30
I think that you will find that egrep and fgrep are symbolic links to grep. Try using grep -E and see if your results are different. The program is supposed to figure out which path executed it and set option -E for egrep and -F for fgrep. It might be broken.
 
Old 02-20-2002, 02:41 AM   #4
Barbarian
Member
 
Registered: Nov 2001
Location: Malaysia and Manchester
Distribution: Red Hat
Posts: 46

Original Poster
Rep: Reputation: 15
Thanks for the information but I've finally managed to come up with a solution by piping a generic grep to awk which does support the full range of metacharacters. It was a real pain and hardly an ideal solution, but hey, it works!

In the end I used something like:-

grep "head" $lListFile | awk '/head( |\t)+[0-9]+(\.[0-9])*;/ { sub(/;/, " ") ; print $2 }'

Any of you clever types out there know any different?

Last edited by Barbarian; 02-20-2002 at 02:42 AM.
 
Old 10-18-2002, 05:42 PM   #5
Silly22
LQ Newbie
 
Registered: Mar 2002
Location: Edmonton, AB
Distribution: Mandrake 10.2, Ubuntu 6.10
Posts: 26

Rep: Reputation: 15
In another post,
neo77777 says
Quote:
Well awk recognizes word delimiters - spaces, tabs. So I pipe the output of grep to the awk
That thread is:
http://www.linuxquestions.org/questi...752#post126752

I myself prefer using vim scripts. It has a very complex regular expressions searching. I've never tried piping to vim; instead, I just pipe to a file and let vim work on the file.

And another solution for spaces using grep at the shell is as follows.

For example:

whatever output | grep -Ee " "*.*" "*[1-9]{1}[0-9]*

the search string for 0 to many spaces is " "*
A quote followed by a space followed by a quote optionally followed by a repetition operator.
 
Old 10-20-2002, 02:54 PM   #6
leed_25
Member
 
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102

Rep: Reputation: 17
what happens if you put an actual space character or tab character in the list? it works for me.
 
  


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
Parsing out html with egrep binaryechoes Linux - Newbie 3 12-02-2005 12:41 AM
egrep multiple files smart_sagittari Linux - Newbie 2 06-27-2005 08:57 AM
egrep question internal_war Linux - Newbie 6 05-05-2005 06:32 PM
Help with egrep smart_sagittari Linux - Newbie 2 05-02-2005 08:18 AM
Using Grep and Egrep linux-nerd Linux - General 5 10-10-2004 11:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:16 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration