linux 中awk命令的几个常用算数函数
001、幂函数(即e的多少次方)
[root@PC1 test02]# ls a.txt [root@PC1 test02]# cat a.txt ## 测试数据 9 1 2 10 [root@PC1 test02]# awk '{print exp($1)}' a.txt ## 幂函数 8103.08 2.71828 7.38906 22026.5
02、自然对数(e的多少次方等于x)
[root@PC1 test02]# ls a.txt [root@PC1 test02]# cat a.txt ## 测试数据 9 1 2 2.71828 10 [root@PC1 test02]# awk '{print log($1)}' a.txt ## 自然对数 2.19722 0 0.693147 0.999999 2.30259
03、求平方根
[root@PC1 test02]# ls a.txt [root@PC1 test02]# cat a.txt 9 1 2 2.71828 10 [root@PC1 test02]# awk '{print sqrt($1)}' a.txt ## 求平方跟 3 1 1.41421 1.64872 3.16228
04、截断数值至整数部分
[root@PC1 test02]# ls a.txt [root@PC1 test02]# cat a.txt 9.8 1.2 2.98 2.71828 10.03 [root@PC1 test02]# awk '{print int($1)}' a.txt ## 截断数值 9 1 2 2 10
05、rand, 取随机数
[root@PC1 test02]# ls a.txt [root@PC1 test02]# cat a.txt 9.8 1.2 2.98 2.71828 10.03 [root@PC1 test02]# awk '{print rand()}' a.txt ## 取随机数, 范围为0~1 0.237788 0.291066 0.845814 0.152208 0.585537
.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-07-13 linux 中实现数据的每一列都对齐
2022-07-13 plink 软件 --hardy参数计算哈代温伯格平衡中 p值的来源
2022-07-13 plink 软件中 --impute-sex 参数
2021-07-13 R语言返回重复的向量以重复向量的索引
2021-07-13 c语言中的整数溢出问题