[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] There are cases where regexp in FPAT does not work
From: |
Wolfgang Laun |
Subject: |
Re: [bug-gawk] There are cases where regexp in FPAT does not work |
Date: |
Sat, 9 Feb 2019 08:06:55 +0100 |
I should have explained this one as well:
$ echo '{{111}} design will serve {{111}} ...' |
awk '{ print FPAT; print $1; print $2; gsub($1,"xxx",$0); print }'
FPAT='{{[0-9]+}}'
{{[0-9]+}}
{{111}}
{{111}}
{{111}} design will serve {{111}} ...
The pattern /{{111}}/ describes a string consisting of 111 times '{'
followed by '}'. Making this a little easier to write, we can observe it
working:
$ echo '{{11}} design will serve {{{{{{{{{{{} ...' | awk '{ print FPAT;
print $1; gsub($1,"xxx",$0); print }' FPAT='\\{\\{[0-9]+\\}\\}'
\{\{[0-9]+\}\}
{{11}}
{{11}} design will serve xxx ...
This is an incomplete effort to make the matched string work as a pattern,
disabling some magic characters:
$ echo '{{111}} design will serve {{111}} ...' | awk '{ print FPAT; print
$1; print $2; h=$1; gsub(/[\][{}*+]/,"\\\\&",h); print h; gsub(h,"xxx",$0);
print }' FPAT='\\{\\{[0-9]+\\}\\}'
\{\{[0-9]+\}\}
{{111}}
{{111}}
\{\{111\}\}
xxx design will serve xxx ...
-W
On Fri, 8 Feb 2019 at 22:46, Hyunho Cho <address@hidden> wrote:
> $ awk --version
> GNU Awk 4.2.1, API: 2.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
> Copyright (C) 1989, 1991-2018 Free Software Foundation.
>
> $ lsb_release -a
> No LSB modules are available.
> Distributor ID: Ubuntu
> Description: Ubuntu 18.10
> Release: 18.10
> Codename: cosmic
>
> $ uname -a
> Linux EliteBook 4.18.0-14-generic #15-Ubuntu SMP Mon Jan 14 09:01:02
> UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
>
>
> #####################################################################
>
>
> There are cases where regexp in FPAT does not work.
> If i change "{{111}}" to "{{AAA}} in input string and
> FPAT='{{[A-Z]+}}' then it WORK
>
>
> ### FPAT='{{[0-9]+}}' NOT WORK!
> $ echo '{{111}} design will serve {{111}} ...' |
> awk '{ gsub($1,"xxx",$0); print }' FPAT='{{[0-9]+}}'
> {{111}} design will serve {{111}} ...
>
> ### FPAT='{{[0-9]+}' NOT WORK!
> $ echo '{{111}} design will serve {{111}} ...' |
> awk '{ gsub($1,"xxx",$0); print }' FPAT='{{[0-9]+}'
> {{111}} design will serve {{111}} ...
>
> ### FPAT='{[0-9]+}' WORK!
> $ echo '{{111}} design will serve {{111}} ...' |
> awk '{ gsub($1,"xxx",$0); print }' FPAT='{[0-9]+}'
> {xxx} design will serve {xxx} ...
>
> ### FPAT='{[0-9]+}}' WORK!
> $ echo '{{111}} design will serve {{111}} ...' |
> awk '{ gsub($1,"xxx",$0); print }' FPAT='{[0-9]+}}'
> {xxx design will serve {xxx ...
>
> ### WORK!
> $ echo '{{111}} design will serve {{111}} ...' |
> awk '{ gsub("{{[0-9]+}}","xxx",$0); print }'
> xxx design will serve xxx ...
>
> ### NOT WORK!
> $ echo '[[111]] design will serve [[111]] ...' |
> awk '{ gsub($1,"xxx",$0); print }' FPAT='\\[\\[[0-9]+]]'
> [[11xxx] design will serve [[11xxx] ...
>
> ### WORK!
> $ echo '[[111]] design will serve [[111]] ...' |
> awk '{ gsub("\\[\\[[0-9]+]]","xxx",$0); print }'
> xxx design will serve xxx ...
>
>