用awk对shu文件中的两列数进行减法运算

[root@localhost ~]# cat shu
22 32
11 3
21 33
32 0
23 55
33 33
44 56
[root@localhost ~]# awk 'BEGIN {print "one two diff\n-----------"} {if ($1<$2) $3=$2-$1;else $3=-($1-$2);print $1,$2,$3} END {print "------------\nend of diff"}' shu
one two diff
-----------
22 32 10
11 3 -8
21 33 12
32 0 -32
23 55 32
33 33 0
44 56 12
------------
end of diff

 

awk的一个实例_linux