在awk的绝对值不工作? [英] Absolute value in awk doesn't work?

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

问题描述

我要选择一个文件,其中列9的绝对值小于500列有时是正面的,有时甚至是负的行。

 的awk -F'\\ t''{如果($ 9 LT; | 500 |){$打印0}}'> output.bam

这不工作至今..一轮互联网上告诉我,使用绝对值我们应该加上

  FUNC ABS(X){返回(X小于0)? X * -1:X}

然后我怎么想将这个带有列9的值一起?我不知道这可能是一个正确的语法。


解决方案

 的awk -F'\\ t''函数ABS(X){回报((X< 0.0) - X:X)} {如果(ABS($ 9)LT; 500)打印$ 0}

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'\t' '{ 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 }

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'\t' 'function abs(x){return ((x < 0.0) ? -x : x)} {if (abs($9) < 500) print $0}'

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

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