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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-23-2010, 07:42 PM
|
#1
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Rep: 
|
awk regex /f[eo]{2}t/ does not work as advertised
Please refer to this article.
Quote:
Specific Repetition
If a regular expression is to be matched a particular number of times, curly brackets ({}) can be used. For example:
/f[eo]{2}t/
This matches "foot" or "feet".
|
Code:
$ awk '/f[eo]{2}t/'
feet
foot
$ ls -l $( which awk )
lrwxrwxrwx 1 root root 21 2009-04-02 11:12 /usr/bin/awk -> /etc/alternatives/awk
$ ls -l /etc/alternatives/awk
lrwxrwxrwx 1 root root 13 2009-04-02 11:12 /etc/alternatives/awk -> /usr/bin/mawk
$ lsb_release -dc
Description: Ubuntu 8.04.4 LTS
Codename: hardy
man awk gives the the manpage for MAWK Version 1.2, and I can not find any reference to the {n} construction therein.
What am I to make of this?
Last edited by Telengard; 07-23-2010 at 07:44 PM.
Reason: remove emoticon
|
|
|
|
07-23-2010, 07:46 PM
|
#2
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
if you use gawk, use the --re-interval or --posix option to enable interval expressions. (ie {}).
|
|
|
|
07-23-2010, 08:00 PM
|
#3
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Original Poster
Rep: 
|
Quote:
Originally Posted by ghostdog74
if you use gawk, use the --re-interval or --posix option to enable interval expressions. (ie {}).
|
Code:
$ whereis gawk
gawk:
As explained in the original post, system came with mawk. I do not have gawk.
Should I just assume that the Awk language is broken on Ubuntu?
|
|
|
|
07-23-2010, 08:05 PM
|
#4
|
|
Member
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 806
Rep: 
|
There are at least two things wrong with that article.
First, it does not recognize that there are several varieties of awk out there. You"re running Kubuntu, right? My wife runs Xubunu, and her awk is mawk, just like yours, and it behaves just like yours. There seems to be no provision therein for interval expressions, and the [KX]ubuntu man page reflects this.
On Slackware, when I ask for awk, I get GNU awk. Run in the normal manner, it doesn't have interval expressions either. But if you run it with the --posix option or the --re-interval option, interval expressions are allowed. Here's my experience with GNU awk:
Code:
evans:~$ awk '/f[eo]{2}t/'
feet
foot
evans:~$ awk --posix '/f[eo]{2}t/'
feet
feet
foot
foot
evans:~$
The second thing wrong with the article is that it seems to have a superficial understanding of regular expressions.
also matches these two lines:
|
|
|
1 members found this post helpful.
|
07-23-2010, 08:12 PM
|
#5
|
|
Member
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 806
Rep: 
|
getting gawk
You can install gawk on your Kubuntu system. Get the package from http://packages.debian.org/stable/gawk
|
|
|
|
07-23-2010, 08:36 PM
|
#6
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Original Poster
Rep: 
|
Thank you for explaining it so well, wje_lq. That leads me to a conclusion and another question or two.
Quote:
Originally Posted by wje_lq
First, it does not recognize that there are several varieties of awk out there. You"re running Kubuntu, right? My wife runs Xubunu, and her awk is mawk, just like yours, and it behaves just like yours.
|
This really irks me. It means Ubuntu users can not share Awk scripts with users of other systems. Ubuntu is one of the most popular Linux distros (maybe the most popular AFAIK), and Awk is broken on it.
What should I do when writing my own scripts to share?
Quote:
also matches these two lines:
|
That is exactly what I thought when I was reading it. "[eo]" is a complete regular expression which matches either "e" or "o", and that regular expression is repeated twice. I wonder if the authors are really so naive or if they are just trying to keep it simple for beginners.
It seems I won't be able to proceed with the tutorial any further unless I install gawk. Maybe I can figure out how to make it work with the alternatives system so that it doesn't break anything which may depend upon idiosyncrasies of mawk.

|
|
|
|
07-23-2010, 08:44 PM
|
#7
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
i am really sceptical about gawk not being present. Why don't you try a find on your system to see if its really installed. the which command is not really foolproof in that it searches for $PATH only.
|
|
|
|
07-23-2010, 09:45 PM
|
#8
|
|
Member
Registered: Jun 2010
Distribution: Fedora
Posts: 289
Rep:
|
I was just using Kubuntu, and I know that when I ran "update-alternatives --all" awk was gawk by default. But anyways, all you have to do is install it if you don't have it. It has a higher priority and update-alternatives will set it as the default alternative automatically. If you ever have to change the alternatives, all you have to do is use "update-alternatives".
Last edited by pr_deltoid; 07-23-2010 at 09:46 PM.
|
|
|
1 members found this post helpful.
|
07-23-2010, 10:59 PM
|
#9
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Original Poster
Rep: 
|
Quote:
|
Originally Posted by prdeltoid
I was just using Kubuntu, and I know that when I ran "update-alternatives --all" awk was gawk by default. But anyways, all you have to do is install it if you don't have it. It has a higher priority and update-alternatives will set it as the default alternative automatically. If you ever have to change the alternatives, all you have to do is use "update-alternatives".
|
Hmm. What version of Kubuntu do you have there? I have not knowingly removed gawk, nor would I.
Code:
$ aptitude search gawk
p gawk - GNU awk, a pattern scanning and processing
p gawk-doc - Documentation for GNU awk
Good to know! Thank you very much for the helpful info, prdeltoid.
Quote:
Originally Posted by ghostdog74
Why don't you try a find on your system to see if its really installed.
|
Code:
$ cd /
$ sudo updatedb
$ locate -ib gawk
/usr/share/doc/gettext-doc/examples/hello-gawk
/usr/share/locale-langpack/en_GB/LC_MESSAGES/gawk.mo
$ find bin/ lib/ opt/ sbin/ usr/ -type f -iname '*gawk*'
usr/share/locale-langpack/en_GB/LC_MESSAGES/gawk.mo
$ aptitude show gawk | grep -i state
State: not installed
Satisfied?
|
|
|
|
07-23-2010, 11:10 PM
|
#10
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
Quote:
Originally Posted by Telengard
Satisfied?
|
the question is , are you satisfied.? If you are not, then download gawk. for normal operations, gawk is just as fast.
|
|
|
|
07-23-2010, 11:30 PM
|
#11
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Original Poster
Rep: 
|
Quote:
Originally Posted by ghostdog74
the question is , are you satisfied.?
|
I was merely responding to your statement that you were skeptical about gawk not being present on my system. I was already convinced that it was not, but you were probably correct to suggest I not rely completely on whereis to determine such.
As to whether I am satisfied, I have mixed feelings about this. I don't understand why my Kubuntu system shipped with a crippled Awk interpreter whereas other people's Kubuntu systems apparently did not. Maybe I should just chalk it up to Ubuntu's fickleness and add it to my list of reasons to move to Slackware.
On the other hand I can't claim that my original post has not been satisfied, so I'll probably mark this one solved for now.
|
|
|
|
07-24-2010, 12:13 AM
|
#12
|
|
Member
Registered: Apr 2007
Location: USA
Distribution: Kubuntu 8.04
Posts: 579
Original Poster
Rep: 
|
Code:
$ gawk --posix '/f[eo]{2}t/'
feet
feet
foot
foot
foet
foet
feot
feot
Okay this is defintely solved now. Thank you everyone for helping. 
|
|
|
|
07-24-2010, 12:27 AM
|
#13
|
|
Member
Registered: Jun 2010
Distribution: Fedora
Posts: 289
Rep:
|
Quote:
|
Hmm. What version of Kubuntu do you have there?
|
I was using Kubuntu 10.4 ...
EDIT:
gawk might have been installed as a dependency when I was installing something else. I installed vim, build-essential, firefox, etc. Since it had a higher priority for update-alternatives, it could've just been made the default after it was installed as a dependency.
Last edited by pr_deltoid; 07-24-2010 at 12:30 AM.
|
|
|
|
07-24-2010, 01:36 AM
|
#14
|
|
Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 6,386
|
I am running Ubuntu 10.04 and confirm that by default gawk is not available and mawk was the only option.
Upon getting more involved with [g]awk scripting I have since removed mawk as it had other limitations too, such as no gensub.
|
|
|
1 members found this post helpful.
|
07-24-2010, 01:43 AM
|
#15
|
|
Member
Registered: Jun 2010
Distribution: Fedora
Posts: 289
Rep:
|
I know that when I was going through the LFS book, it said to make sure that gawk was used, because mawk could not do the things that had to be done. I was using Debian, and it was using mawk by default.
|
|
|
1 members found this post helpful.
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:36 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
|
|