awk 中的绝对值不起作用? [英] Absolute value in awk doesn't work?

查看:39
本文介绍了awk 中的绝对值不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想选择第 9 列的绝对值小于 500 的文件行.列有时为正,有时为负.

I want to select line of a file where the absolute value of column 9 is less than 500. Column is sometimes positive, sometimes negative.

awk -F'	' '{ if ($9 < |500|) {print $0} }' > output.bam

到目前为止这不起作用..互联网上的一轮告诉我,要使用我们应该添加的绝对值

This doesn't work so far .. one round on internet told me that to use the absolute value we should add

func abs(x) { return (x<0) ? x*-1 : x }

那我怎么把它和第 9 列的值放在一起??我不知道什么是正确的语法..

Then how am I suppose to put this along with the value of column 9?? I don't know what could be a proper syntax..

推荐答案

awk -F'	' 'function abs(x){return ((x < 0.0) ? -x : x)} {if (abs($9) < 500) print $0}'

这篇关于awk 中的绝对值不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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