bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: gawk: numeric comparison on 'sub()' resulted ${n} vars does not wor


From: Stephen Dowdy
Subject: Fwd: gawk: numeric comparison on 'sub()' resulted ${n} vars does not work properly
Date: Sat, 8 Feb 2020 10:33:50 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0

This bug i filed for 'mawk' (via Debian) also affects 'gawk' (hope you don't 
mind the cut/paste)

Bug#950894: Acknowledgement (mawk: numeric comparison on 'sub()' resulted ${n} 
vars does not work properly)
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=950894

thanks,
--stephen


-------- Forwarded Message --------
Subject: mawk: numeric comparison on 'sub()' resulted ${n} vars does not work 
properly
Date: Fri, 07 Feb 2020 13:59:33 -0700
From: Stephen Dowdy <address@hidden>
To: Debian Bug Tracking System <address@hidden>

Package: mawk
Version: 1.3.3-17+b3
Severity: normal

Dear Maintainer,

NOTE: this affects both 'mawk' and 'gawk' equally, so i'm not sure if this is some 
utterly esoteric behavior i'm just not "getting", but my expectations are 
definitely not being met.
(i also am unaware if a bug can be co-assigned to different packages)

Attempting to do a search for filesystems > 90% inode % or size % was giving 
anomolous results. (hair-pulling time)

I was using 'sub("%","",$1) to strip the % symbol off the results from:
    df --output=ipcent,pcent,target /var /var/log
e.g.:
    $ df --output=ipcent,pcent,target -t ext4  | mawk 
'NR>1{sub("%","",$1);sub("%","",$2); if (($1>30)||($2>30)) print}'
    40 79 /
    6 30 /var
    1 7 /opt
    20 78 /home
    1 89 /d1
(clearly /opt doesn't meet the reporting criteria)

I narrowed this down to what appears to be a field-size truncation comparison 
issue with the result from the sub() against the comparison numeric on the 
right-side of the relop:

# The following all work as expected: (no output)
$ for i in $(seq 20 29); do echo "$i%" | mawk '{if (int($1)>100) print}'; done
$ for i in $(seq 20 29); do echo "$i%" | gawk '{if (int($1)>100) print}'; done
$ for i in $(seq 20 29); do echo "$i%" | mawk '{if (($1+0)>100) print}'; done
$ for i in $(seq 20 29); do echo "$i%" | gawk '{if (($1+0)>100) print}'; done

This does NOT work, though it should: (none of these values should print, they are 
all < 100, which is the comparison being made)
$ for i in $(seq 20 29); do echo "$i%" | mawk '{sub("%","",$1);if ($1>100) 
printf("[%s][%d]\n",$1,$1)}'; done
[20][20]
[21][21]
[22][22]
[23][23]
[24][24]
[25][25]
[26][26]
[27][27]
[28][28]
[29][29]

The man pages clearly state that a dual-type (numeric&string) variable SHOULD 
be implicitly cast to numeric if a comparison is against a numeric.

I also did this against a single digit input and a two-digit RHS value, and it 
shows the same issue, where only the same number of digits of the RHS that the 
input value contain are being compared.
$ for i in $(seq 0 20); do echo "$i%" | gawk '{sub("%","",$1);if ($1>40) 
printf("[%s][%d]\n",$1,$1)}'; done
[5][5]
[6][6]
[7][7]
[8][8]
[9][9]

Using an RHS of a float also fails:
$ for i in $(seq 0 20); do echo "$i%" | gawk '{sub("%","",$1);if ($1>40.0) 
printf("[%s][%d]\n",$1,$1)}'; done
[5][5]
[6][6]
[7][7]
[8][8]
[9][9]

I don't know how if there's a way to evaluate the internal data-type 
representation for $1 here, so i printed it with printf both as string and 
integer, and they report identical.

Thanks,
--stephen


-- System Information:
Debian Release: 10.2
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'proposed-updates'), (500, 
'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.19.0-7-amd64 (SMP w/16 CPU cores)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE, 
TAINT_UNSIGNED_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE= 
(charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages mawk depends on:
ii  libc6  2.28-10

mawk recommends no packages.

mawk suggests no packages.

-- no debconf information



reply via email to

[Prev in Thread] Current Thread [Next in Thread]