[英]How do I increase a float value in a text file using bash on Linux?
$猫订单
2016 apples .20
2016 oranges .10
2013 bananas .17
2016 berries .30
我想将每个水果的成本增加0.02
2016 apples .22
2016 oranges .12
2013 bananas .19
2016 berries .32
在Linux中使用bash完成此操作的最简单方法是什么?
这是使用awk的快速单线
awk 'NF>=3{$3+=0.02}1' orders
如果价格始终低于.98并始终带有两位数:
echo "2016 apples .20
2016 oranges .10
2013 bananas .17
2016 berries .30" | while read year fruit preis
do
price=${preis/./}
echo year fruit .$((price+2))
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.