help-gawk
[Top][All Lists]
Advanced

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

ensure numeric comparison


From: Peng Yu
Subject: ensure numeric comparison
Date: Fri, 6 May 2022 17:28:39 -0500

Hi,

I want to make sure whether the following code is guaranteed to
compare $1 and $2 numerically as long as the input of the 1st and 2nd
fields are legitimate numbers or empty strings (which are considered
as 0).

awk -e '{ print ($1 < $2) }' < input

Or there is any corner case when even the 1st and 2nd fields are
legitimate numbers or empty strings, they may be compared as strings.

Note although an empty string compared with an empty string is a
string comparison, the result is the same as 0 and 0 comparison, so it
is still effectively considered as a numerical comparison for the
current discussion.

-- 
Regards,
Peng



reply via email to

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