[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 回复: 回复: report a bug of the function of patsplit
From: |
Andrew J. Schorr |
Subject: |
Re: 回复: 回复: report a bug of the function of patsplit |
Date: |
Tue, 18 Aug 2020 20:41:34 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
I ask you please again always to CC the bug list instead of responding
privately. Thanks. And I still think that you misunderstand how patsplit
works. Please consider using split instead; maybe that will give you the
results that you expect. If you think the results of patsplit are wrong,
please tell us what you think they should be.
bash-4.2$ echo "xnapsevt cnaps mmnasten" | gawk '{ patsplit($0, pieces_array,
"na",sep_array)} END{ for(x in pieces_array){ print"pieces_array[" x "]="
pieces_array[x]}; for(y in sep_array){ print "sep_array[" y "]=",
sep_array[y]}}'
pieces_array[1]=na
pieces_array[2]=na
pieces_array[3]=na
sep_array[0]= x
sep_array[1]= psevt c
sep_array[2]= ps mm
sep_array[3]= sten
bash-4.2$ echo "xnapsevt cnaps mmnasten" | gawk '{ split($0, pieces_array,
"na",sep_array)} END{ for(x in pieces_array){ print"pieces_array[" x "]="
pieces_array[x]}; for(y in sep_array){ print "sep_array[" y "]=",
sep_array[y]}}'
pieces_array[1]=x
pieces_array[2]=psevt c
pieces_array[3]=ps mm
pieces_array[4]=sten
sep_array[1]= na
sep_array[2]= na
sep_array[3]= na
bash-4.2$
Regards,
Andy
On Wed, Aug 19, 2020 at 05:36:39AM +0800, 天骄之鹰 wrote:
> hi guys:
> I want to save pieces("xnapsevt cnaps mmnasten) into "pieces_array", to
> save "fieldpat" into "sep_array". the fact , the pieces are stored in
> "sep_array", the sep are stored in "pieces_array". So , i think i find a bug
> about patsplit function.
>
>
>
> tip1:
> [root@novice awk]# echo "xnapsevt cnaps mmnasten" | awk '{ patsplit($0,
> pieces_array, "na",sep_array)} END{ for(x in pieces_array){ print"pieces_array
> [" x "]=" pieces_array[x]}; for(y in sep_array){ print "sep_array[" y "]=",
> sep_array[y]}}'
> pieces_array[1]=na
> pieces_array[2]=na
> pieces_array[3]=na
> sep_array[0]= x
> sep_array[1]= psevt c
> sep_array[2]= ps mm
> sep_array[3]= sten
> [root@novice awk]# gawk -V
>
>
> tip2:
> patsplit(string, array [, fieldpat [, seps ] ]) #
>
> Divide string into pieces (or “fields”) defined by fieldpat and store the
> pieces in array and the separator strings in the seps array. The first
> piece is stored in array[1], the second piece in array[2], and so forth.
> The third argument, fieldpat, is a regexp describing the fields in string
> (just as FPAT is a regexp describing the fields in input records). It may
> be either a regexp constant or a string. If fieldpat is omitted, the value
> of FPAT is used. patsplit() returns the number of elements created.
> seps[i]
> is the possibly null separator string after array[i]. The possibly null
> leading separator will be in seps[0]. So a non-null string with n fields
> will have n+1 separators. A null string will not have neither fields nor
> separators.
>
> The patsplit() function splits strings into pieces in a manner similar to
> the way input lines are split into fields using FPAT (see section Defining
> Fields by Content).
>
> Before splitting the string, patsplit() deletes any previously existing
> elements in the arrays array and seps. ( the informations come from
> https:/
> /www.gnu.org/software/gawk/manual/gawk.html#String-Functions)
>
>
>
> tips3:
> [root@novice awk]# gawk -V
> GNU Awk 5.1.0, API: 3.0
> Copyright (C) 1989, 1991-2020 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/.
> [root@novice awk]# uname -a
> Linux novice 4.18.0-193.14.2.el8_2.x86_64 #1 SMP Sun Jul 26 03:54:29 UTC
> 2020 x86_64 x86_64 x86_64 GNU/Linux
> [root@novice awk]#
>
>
>
> tips4:
> [root@novice awk]# uname -a
> Linux novice 4.18.0-193.14.2.el8_2.x86_64 #1 SMP Sun Jul 26 03:54:29 UTC
> 2020 x86_64 x86_64 x86_64 GNU/Linux
> [root@novice awk]#
> os = centos8.1
>
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> 天才就是毅力!
>
>
>
> ------------------ 原始邮件 ------------------
> 发件人: "Andrew J. Schorr" <aschorr@telemetry-investments.com>;
> 发送时间: 2020年8月19日(星期三) 凌晨4:32
> 收件人: "天骄之鹰"<tianjiaozhiying@qq.com>;
> 抄送: "bug-gawk"<bug-gawk@gnu.org>;
> 主题: Re: 回复: report a bug of the function of patsplit
>
> Hi,
>
> Please always respond to the list instead of privately.
> You answered half of my question, but not the more important half: how
> do the results differ from what you expect? As Wolfgang pointed out,
> the patsplit function seems to be working correctly, as far as I can tell.
> And yes -- you should upgrade to the newest version of gawk.
>
> Regards,
> Andy
>
> On Wed, Aug 19, 2020 at 04:27:14AM +0800, 天骄之鹰 wrote:
> >
> > My system informations:
> >
> >
> > // awk version
> > [root@novice ~]# awk --version
> > GNU Awk 4.2.1, API: 2.0 (GNU MPFR 3.1.6-p2, GNU MP 6.1.2)
> > Copyright (C) 1989, 1991-2018 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/.
> >
> >
> > // my OS informations:
> > [root@novice ~]# uname -a
> > Linux novice 4.18.0-193.14.2.el8_2.x86_64 #1 SMP Sun Jul 26 03:54:29 UTC
> 2020
> > x86_64 x86_64 x86_64 GNU/Linux
> > [root@novice ~]#
> > OS = centos8.1
> >
> >
> > I think that the bug of patsplit maybe repair in the new versions. thank
> you
> > for your reply. good luck.
> >
> >
> >
> >
>
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> > ž
> >
> >
> >
> > ------------------ ԭʼ ------------------
> > : "Andrew J. Schorr" <aschorr@telemetry-investments.com>;
> > ʱ : 2020 8 18 ( ) 11:34
> > : " ֮ӥ"<tianjiaozhiying@qq.com>;
> > : "bug-gawk"<bug-gawk@gnu.org>;
> > : Re: report a bug of the function of patsplit
> >
> > Hi,
> >
> > Thanks for the bug report. Which version of gawk are you using, and how
> do the
> > results differ from what you expect?
> >
> > Regards,
> > Andy
> >
> > On Tue, Aug 18, 2020 at 01:25:16PM +0800, ֮ӥ wrote:
> > > Hi, guys:
> > >
> > >
> > > I find that the function of patsplit has a bug.
> > >
> > >
> > > patsplit(string, array [, fieldpat[, seps]]) : To save
> pieces
> > into 'array', store separator into 'seps'. But this function saves
> pieces
> into
> > 'seps', not strore into 'array'
> > >
> > >
> > >
> > >
> > >
> > >
> > > // souce codes
> > > [root@novice commands]# echo "chinaos cnaps mmnasten" | gawk '{
> patsplit($0,
> > arr,"na", sepp )} END{ for( x in arr){ print "arr[" x "]=" arr[x]}; for(
> y in
> > sepp){ print "sepp[" y "]=", sepp[y]}}'
> > > arr[1]=na
> > > arr[2]=na
> > > arr[3]=na
> > > sepp[0]= chi
> > > sepp[1]= os c
> > > sepp[2]= ps mm
> > > sepp[3]= sten
> > >
> > >
> > >
> > > [root@novice commands]# echo "chinaos cnaps mmnasten" | gawk '{
> patsplit($0,
> > arr,"na", sepp )} END{ for( x in arr){ print "arr[" x "]=" arr[x]}; for(
> y in
> > sepp){ print "sepp[" y "]=", sepp[y]}}'
> > > arr[1]=na
> > > arr[2]=na
> > > arr[3]=na
> > > sepp[0]= chi
> > > sepp[1]= os c
> > > sepp[2]= ps mm
> > > sepp[3]= sten
> > >
> > >
> > >
> > >
> > >
> > > Good luck.
> > >
> > > ž
> > >
> > >
> > >
>
> --
> Andrew Schorr e-mail:
> aschorr@telemetry-investments.com
> Telemetry Investments, L.L.C. phone: 917-305-1748
> 152 W 36th St, #402 fax: 212-425-5550
> New York, NY 10018-8765
--
Andrew Schorr e-mail: aschorr@telemetry-investments.com
Telemetry Investments, L.L.C. phone: 917-305-1748
152 W 36th St, #402 fax: 212-425-5550
New York, NY 10018-8765
Re: report a bug of the function of patsplit, arnold, 2020/08/19