铸造在awk来诠释 [英] casting to int in awk

查看:106
本文介绍了铸造在awk来诠释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找投字符串为int在AWK的方法。我有这似乎是做一个字符串比较以下

I'm looking for a method to cast a string to an int in awk. I have the following which appears to be doing a string comparison

注意:场$ 5是两种格式之一的百分比; 80%或9.0%)

(note: field $5 is a percentage in one of two formats; 80% or 9.0%)


AWK'{如果(SUBSTR($ 5,1,(长($ 5)-1))> = 90)...

所以,当我将其更改为:

So, when I change it to:


AWK'{如果(SUBSTR($ 5,1,(长($ 5)-1))+ 0> = 90 + 0)...

它比较像我意。这是一个合适的投?是否有一个'好'的方式来执行转换?

It compares as I intended. Is this an appropriate cast? Is there a 'better' way to perform the cast?

推荐答案

您可以只使用+ 0。说变量 v 是百分比值。

You can just use +0. say variable v is your percentage value.

$ awk -v v="80.1%" 'BEGIN{print v+0.1}'
80.2

您不必摆脱标志。

这篇关于铸造在awk来诠释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆