How to subtract a constant number from a column

杀马特。学长 韩版系。学妹 提交于 2019-11-30 03:42:50

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 

You were on the right track:

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

Here is a simplified version of Michael's second example:

awk 'NR == 1 {origin = $1} {$1 = $1 - origin; print}' file

bash shell script

#!/bin/bash

exec 4<"file"
read col1 col2<&4
while read -r n1 n2 <&4
do
  echo $((n1-$col1))
  # echo "scale=2;$n1 - $col1" | bc # dealing with decimals..
done
exec >&4-
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!