AWK比小于而是一组范围内更大 [英] Awk greater than less than but within a set range
问题描述
我有一个脚本,基本上evaulates 2十进制数。
I have a script that basically evaulates 2 decimal numbers.
if (( $(echo "$p $q" | awk '{ print ($1 < $2)}') )); then
echo "Evaluation: Acceptable!"
q是用户输入小数或数字。结果
p是一个计算的数字。
q is a decimal or number from user input.
p is a calculated figure.
因此,如果p = 1和q = 2,则结果是可接受的。
Consequently, if p=1, and q=2, then the outcome is Acceptable.
问题1结果
我们如何evaulate它是不能接受的,如果计算出的p是-150,而Q = 2。基本上,如果p小于0或负值时,结果应该是不可接受的。
Question#1
How do we evaulate it to be UNacceptable if the calculated p is -150, while q=2. Basically, if p is less than 0 or a negative value, the outcome should be UNacceptable.
问题2结果
q是一个范围:-q&LT; 0℃; q结果
例如:用户输入Q = 0.01结果
可接受范围:-0.01至0.01结果
如果p是该范围内,则这是可以接受,否则不能接受的。
Question#2
q is a range: -q < 0 < q
Example: User input q=0.01
Acceptable range: -0.01 to 0.01
If p is within this range, then it's acceptable, else UNacceptable.
任何想法?
推荐答案
我觉得这AWK应该够你:
I think this awk should be enough for you:
awk '{print ($1 > 0 && $1 < $2)}'
关于您的需求#2:
About your requirement # 2:
由于任何不能通过p为负按要求#1所以只是检查 $ 1&LT; $ 2
足够你。
Since any p cannot be negative as per requirement #1 therefore just checking $1 < $2
is enough for you.
这篇关于AWK比小于而是一组范围内更大的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!