[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mawk vs gawk: match() difference -- bug? (correct version)
From: |
arnold |
Subject: |
Re: mawk vs gawk: match() difference -- bug? (correct version) |
Date: |
Wed, 30 Dec 2020 11:22:14 -0700 |
User-agent: |
Heirloom mailx 12.5 7/5/10 |
Hi.
Thanks for the report.
It's not a bug. Gawk accepts additional regexp operators \` and \'. If
you run gawk with --traditional or --posix, you will get the same
output as from mawk.
If you need literal ` or ' in your regexp, use [`] and ['] (or just
don't precede them with backslashes) and then you won't run into the problem.
Also, 4.1.3 is 5 years old; the current version is 5.1.0. I suggest
upgrading, even if you have to build from source; doing so isn't hard.
Thanks!
Arnold
Richard <rgollub@gmx.com> wrote:
> Find below the difference between gawk and mawk regardinng the match()
> built-in function: mawk reacts as expected whilst gawk does not. Hence
> the question: is it a bug?
>
> <quote>
> $ cat test.awk
> BEGIN {
> str = "`abcdefghijklmnopqrstuvwxyz` # rest of string"
> pat = "^\\`[^\\`]*(\\`|\\\\$)"
> pos = match(str, pat)
> print "str = \"" str "\""
> print "pat = \"" pat "\""
> print "pos = " pos
> print "RSTART = " RSTART
> print "RLENGTH = " RLENGTH
> print "substr = \"" substr(str, RSTART, RLENGTH) "\""
> }
>
> $ sudo update-alternatives --config awk
> There are 2 choices for the alternative awk (providing /usr/bin/awk).
>
> Selection Path Priority Status
> ------------------------------------------------------------
> 0 /usr/bin/gawk 10 auto mode
> 1 /usr/bin/gawk 10 manual mode
> * 2 /usr/bin/mawk 5 manual mode
>
> Press <enter> to keep the current choice[*], or type selection number: 1
> update-alternatives: using /usr/bin/gawk to provide /usr/bin/awk (awk)
> in manual mode
>
> $ awk -Wv
> GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)
> Copyright (C) 1989, 1991-2015 Free Software Foundation.
>
> This program is free software; you can redistribute it and/or modify
> it under the terms of the GNU General Public License as published by
> the Free Software Foundation; either version 3 of the License, or
> (at your option) any later version.
>
> This program is distributed in the hope that it will be useful,
> but WITHOUT ANY WARRANTY; without even the implied warranty of
> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> GNU General Public License for more details.
>
> You should have received a copy of the GNU General Public License
> along with this program. If not, see http://www.gnu.org/licenses/.
>
> $ awk -f test.awk
> str = "`abcdefghijklmnopqrstuvwxyz` # rest of string"
> pat = "^\`[^\`]*(\`|\\$)"
> pos = 1
> RSTART = 1
> RLENGTH = 0
> substr = ""
>
> $ sudo update-alternatives --config awk
> There are 2 choices for the alternative awk (providing /usr/bin/awk).
>
> Selection Path Priority Status
> ------------------------------------------------------------
> 0 /usr/bin/gawk 10 auto mode
> * 1 /usr/bin/gawk 10 manual mode
> 2 /usr/bin/mawk 5 manual mode
>
> Press <enter> to keep the current choice[*], or type selection number: 2
> update-alternatives: using /usr/bin/mawk to provide /usr/bin/awk (awk)
> in manual mode
> $ awk -Wv
> mawk 1.3.3 Nov 1996, Copyright (C) Michael D. Brennan
>
> compiled limits:
> max NF 32767
> sprintf buffer 2040
>
> $ awk -f test.awk
> str = "`abcdefghijklmnopqrstuvwxyz` # rest of string"
> pat = "^\`[^\`]*(\`|\\$)"
> pos = 1
> RSTART = 1
> RLENGTH = 28
> substr = "`abcdefghijklmnopqrstuvwxyz`"
> </quote>