Shell numerical calculation, fractional calculation

Source: Internet
Author: User

In a shell script, you can perform numerical calculations,


Shell small number calculation
Complete with Bc,awk and Nawk tools, etc.
The code for using BC is as follows:

click=`awk -F"\t" ‘$1==2 {print $2}‘ ctr_result.txt`show=`awk -F"\t" ‘$1==1 {print $2}‘ ctr_result.txt`ctr=`echo "scale=4;$click/$show"| bc`
其中,echo "scale=4;$click/$show"| bc完成小数计算,scale参数指定小数点后的保留位数,这里保留4位。ctr_result.txt内容为         1 12        2 10通过awk获取两个参数当然,也可以直接用awk完成小数计算:    。。。

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Shell numerical calculation, fractional calculation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.