手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

AWK操作字符串的截取

[日期:2013-03-21] 来源:Linux社区  作者:songxixi [字体: ]

以下验证结果:

Random number greater than 200 --- 25552

Throw of the dice = 5

[root@Slave02 shell]#

random number less than 500 --- 0

Random number greater than 200 --- 9765

Throw of the dice = 2

[root@Slave02 shell]#

Random number greater than 200 --- 31180

Throw of the dice = 10

[root@Slave02 shell]#

[root@Slave02 shell]# sh random2.sh
 Random number between 0 and 1 = 0.246062
 [root@Slave02 shell]# sh random2.sh
 Random number between 0 and 1 = 0.619153
 [root@Slave02 shell]# sh random2.sh
 Random number between 0 and 1 = 0.619153
 [root@Slave02 shell]# sh random2.sh
 Random number between 0 and 1 = 0.619153
 [root@Slave02 shell]# sh random2.sh
 Random number between 0 and 1 = 0.619153
 [root@Slave02 shell]# sh random2.sh
 Random number between 0 and 1 = 0.201116
 [root@Slave02 shell]# cat random2.sh
 #!/bin/bash
 

AWKSCRIPT='{ srand(); print rand() }'    -srand中伪随机的计算
 

echo -n "Random number between 0 and 1 = "
 echo | awk "$AWKSCRIPT"

exit 0
 [root@Slave02 shell]#

linux
相关资讯       awk  AWK字符串操作  AWK字符串 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款