如何从柱减去恒定数量 [英] how to subtract a constant number from a column

查看:108
本文介绍了如何从柱减去恒定数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有另一种方式从列的所有值中减去最小值,有效地抵消了价值?
我必须从所有其他号码减去第一个数字,在格兰第一列,在格兰第一列..
   我写这个剧本是不能做出正确的结果。任何人可以帮助我吗?

 的awk'{$ 1 = $ 1  -  1280449530}'文件1280449530 452
1280449531 2434
1280449531 2681
1280449531 2946
1280449531 1626
1280449532 3217
1280449532 4764
1280449532 4501
1280449532 3372
1280449533 4129
1280449533 6937
1280449533 6423
1280449533 4818
1280449534 4850
1280449534 8980
1280449534 8078
1280449534 6788
1280449535 5587
1280449535 10879
1280449535 9920
1280449535 8146
1280449536 6324
1280449536 12860
1280449536 11612


解决方案

您有什么本质上的作品,你只是没有将其输出。你想要什么这将输出:

 的awk'{打印($ 1  -  1280449530),$ 2}'文​​件

您也可以稍微聪明,并不难code的偏移量:

 的awk'{
       如果(NR == 1){
           移= $ 1
       }       打印($ 1 - 移)$ 2
}'文件

Is there a another way to subtract the smallest value from all the values of a column, effectively offset the values? I have to subtract the first number in teh 1st column from all other numbers in teh first column.. I wrote this script which is not giving the right result . can anybody help me ?

awk '{$1 = $1 - 1280449530}' file 

1280449530 452
1280449531 2434
1280449531 2681
1280449531 2946
1280449531 1626
1280449532 3217
1280449532 4764
1280449532 4501
1280449532 3372
1280449533 4129
1280449533 6937
1280449533 6423
1280449533 4818
1280449534 4850
1280449534 8980
1280449534 8078
1280449534 6788
1280449535 5587
1280449535 10879
1280449535 9920
1280449535 8146
1280449536 6324
1280449536 12860
1280449536 11612

解决方案

What you have essentially works, you're just not outputting it. This will output what you want:

awk '{print ($1 - 1280449530) " " $2}' file

You can also be slightly cleverer and not hardcode the shift amount:

awk '{
       if(NR == 1) {
           shift = $1
       }

       print ($1 - shift) " " $2
}' file 

这篇关于如何从柱减去恒定数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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