免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: tomer
打印 上一主题 下一主题

[文本处理] 使用AWK求最大值 [复制链接]

论坛徽章:
145
技术图书徽章
日期:2013-10-01 15:32:13戌狗
日期:2013-10-25 13:31:35金牛座
日期:2013-11-04 16:22:07子鼠
日期:2013-11-18 18:48:57白羊座
日期:2013-11-29 10:09:11狮子座
日期:2013-12-12 09:57:42白羊座
日期:2013-12-24 16:24:46辰龙
日期:2014-01-08 15:26:12技术图书徽章
日期:2014-01-17 13:24:40巳蛇
日期:2014-02-18 14:32:59未羊
日期:2014-02-20 14:12:13白羊座
日期:2014-02-26 12:06:59
11 [报告]
发表于 2014-01-27 09:50 |只看该作者
回复 9# elu_ligao

M for Maximum value

# It's OK for Normal data with positive number ( > 0 )
$ echo -e "-5\n-3\n7\n12\n3" | awk 'M<$1{M=$1}END{print M}'
12

# got the issue when all data were negative number ( < 0 )
# Note: The M will be 0, zero number, when we use it in number, M < $1,
# and the M didn't be assign and be empty
$ echo -e "-3\n-5\n-7\n-12\n-3" | awk 'M<$1{M=$1}END{print M}'


# check M variable to assign to the first number
$ echo -e "-5\n-3\n-7\n-12\n-3" | awk 'M==""||M<$1{M=$1}END{print M}'
-3

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP