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
复制代码

 .

 

posted @   小鲨鱼2018  阅读(195)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!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语言中的整数溢出问题
点击右上角即可分享
微信分享提示