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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-15-2002, 02:27 AM
|
#1
|
Member
Registered: Nov 2001
Location: Malaysia and Manchester
Distribution: Red Hat
Posts: 46
Rep:
|
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.
|
|
|
02-18-2002, 01:57 AM
|
#2
|
Member
Registered: Nov 2001
Location: Malaysia and Manchester
Distribution: Red Hat
Posts: 46
Original Poster
Rep:
|
In answer to my own question, it appears that egrep doesn't support the shorthand metacharacters (which is a bit of a shame)
|
|
|
02-18-2002, 04:16 PM
|
#3
|
Member
Registered: Jan 2002
Location: Galveston Island
Distribution: suse, redhat
Posts: 208
Rep:
|
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.
|
|
|
02-20-2002, 02:41 AM
|
#4
|
Member
Registered: Nov 2001
Location: Malaysia and Manchester
Distribution: Red Hat
Posts: 46
Original Poster
Rep:
|
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.
|
|
|
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:
|
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.
|
|
|
10-20-2002, 02:54 PM
|
#6
|
Member
Registered: Jul 2002
Location: san francisco
Distribution: freebsd
Posts: 102
Rep:
|
what happens if you put an actual space character or tab character in the list? it works for me.
|
|
|
All times are GMT -5. The time now is 10:23 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|