Awk的新手.努力与负数格式 [英] New to Awk. Struggling with negative number formatting

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

问题描述

目标:仅输出大于1且小于-1的数据

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

输出介于1到-1之间的数据

output data that is between 1 and -1

我有awk的基础知识,可以打印第2列(我的数据在其中) 注意,我还指定了0-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

我还需要输入行号,所以我添加了NR ...

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

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

为确保我清楚,重点是要确定哪些数据行超出可接受范围,因此我们可以在分析中忽略它们. (即,任何大于1或小于-1的更改都太大了.)

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.

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天全站免登陆