新来awk中。与负数格式化挣扎 [英] New to Awk. Struggling with negative number formating

查看:326
本文介绍了新来awk中。与负数格式化挣扎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:只输出数据高于1和低于-1

这是1之间,输出数据-1

我有AWK的基础,并可以打印第2列(我的数据)
注意我还指定了一系列0-1

 的awk'/ [0-1] / {$打印2}TEST.DAT

我也需要有行号,所以我说NR ...

 的awk'/ [0-1] / {$打印2 NR}'TEST.DAT

要确保我很清楚,关键是要确定哪些数据线是可以接受的范围之外,所以我们可以在我们的分析中忽略它们。 (即任何大于1或小于-1太大的变化)。

任何帮助,您可以提供将是巨大的。下面我粘贴一些样本数据。谢谢!

http://pastebin.com/7tpBAqua


解决方案

 的awk -F'[,]''NR大于2 {为(i = 2; I< = NF;我++)如果($ I< -1 || $ I> 1){打印NR;接下来}}'文件

Goal: to output only data that is above 1 and below -1

or

output data that is between 1 and -1

I have the basics of awk and can print column 2 (where my data is) notice I also specified a range of 0-1

awk '/[0-1]/  {print $2}' test.dat

I am also needing to have the line number so I added NR...

awk '/[0-1]/  {print $2 NR}' test.dat

To make sure I am clear, the point is to identify which lines of the data are outside of the acceptable range, so we can ignore them in our analysis. (ie anything bigger than 1 or lower than -1 is too much of a change).

Any help you can provide would be great. I have pasted some sample data below. Thanks!

http://pastebin.com/7tpBAqua

解决方案

awk -F'[ ,]' 'NR>2{for (i=2;i<=NF;i++) if ($i<-1 || $i>1) { print NR; next } }' file

这篇关于新来awk中。与负数格式化挣扎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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