Date: Fri, 27 Jul 2001 17:04:26 -0400 From: parv <parv_@yahoo.com> To: jasonla@pobox.com Cc: freebsd-questions@freebsd.org Subject: Re: Regular Expression Help Message-ID: <20010727170426.A51524@moo.holy.cow> In-Reply-To: <20010727201429.24359.qmail@web4605.mail.yahoo.com>; from jasonla00@yahoo.com on Fri, Jul 27, 2001 at 01:14:29PM -0700 References: <20010727201429.24359.qmail@web4605.mail.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
on Jul 27 16:43, i got this from Jason...
> I am looking for a little regular expression help, namely
> with the "{}" operators. Below is the file (inventory.txt)
> that I am working with.
>
> Jan 13 25 15 115
> Jun 31 42 75 492
> Jul 24 34 67 436
> June 19 23 0 846
> Jaa 19 23 0 846
>
> I want to match a line that begins with "J" and then has 2
> letters after it. SO, all of the above should match except
> for "June"
>
> Here is the regular expression that I'm using (in gawk):
>
> gawk '/^J[a-zA-Z]{2}/ {print}' inventory.txt
>
> My problem is that nothing is matched... or at least
> nothing is printed on screen and I assume that nothing is
> matched.
>
> I have tried putting paranthesis around the character list,
> but that didn't work either. The brace operators are
> supposed to match the preceding regualar expression the
> specified number of times, right? Am I not understanding
> the use of the braces operators?
try man (g)awk...
r{n}
r{n,}
r{n,m} One or two numbers inside braces denote an
interval expression. If there is one number in
the braces, the preceding regexp r is repeated
Free Software Foundation May 17 2000 11
GAWK(1) Utility Commands GAWK(1)
n times. If there are two numbers separated by
a comma, r is repeated n to m times. If there
is one number followed by a comma, then r is
repeated at least n times.
Interval expressions are only available if
either --posix or --re-interval is specified on
the command line.
...then try this...
# gawk --posix '/^J[a-zA-Z]{2} / {print $0}' inventory.txt
...or, depending on locale, you may prefer...
# gawk --posix '/^J[[:alpha:]]{2} / {print $0}' inventory.txt
...in any case you need a space in there, otherwise you would also
match the 'June' line. i added '$0' for my own comfort.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010727170426.A51524>
