Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-15-2002, 02:27 AM   #1
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]+;',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
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
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
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
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
Well awk recognizes word delimiters - spaces, tabs. So I pipe the output of grep to the awk
That thread is:

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
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.


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 > Forums > Non-*NIX Forums > Programming

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

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